View | Details | Raw Unified | Return to bug 26282
Collapse All | Expand All

(-)a/C4/Reserves.pm (-1 / +4 lines)
Lines 933-938 Cancels all reserves with an expiration date from before today. Link Here
933
933
934
sub CancelExpiredReserves {
934
sub CancelExpiredReserves {
935
    my $cancellation_reason = shift;
935
    my $cancellation_reason = shift;
936
    my $notify = shift;
936
    my $today = dt_from_string();
937
    my $today = dt_from_string();
937
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
938
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
938
    my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay');
939
    my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay');
Lines 957-962 sub CancelExpiredReserves { Link Here
957
958
958
        my $cancel_params = {};
959
        my $cancel_params = {};
959
        $cancel_params->{cancellation_reason} = $cancellation_reason if defined($cancellation_reason);
960
        $cancel_params->{cancellation_reason} = $cancellation_reason if defined($cancellation_reason);
961
        $cancel_params->{notify_patron} = $notify if defined($notify);
960
        if ( defined($hold->found) && $hold->found eq 'W' ) {
962
        if ( defined($hold->found) && $hold->found eq 'W' ) {
961
            $cancel_params->{charge_cancel_fee} = 1;
963
            $cancel_params->{charge_cancel_fee} = 1;
962
        }
964
        }
Lines 1032-1037 sub ModReserve { Link Here
1032
    my $biblionumber = $params->{'biblionumber'};
1034
    my $biblionumber = $params->{'biblionumber'};
1033
    my $cancellation_reason = $params->{'cancellation_reason'};
1035
    my $cancellation_reason = $params->{'cancellation_reason'};
1034
    my $date = $params->{expirationdate};
1036
    my $date = $params->{expirationdate};
1037
    my $notify_patron = $params->{'notify_patron'};
1035
1038
1036
    return if defined $rank && $rank eq "n";
1039
    return if defined $rank && $rank eq "n";
1037
1040
Lines 1053-1059 sub ModReserve { Link Here
1053
    my $original = C4::Context->preference('HoldsLog') ? $hold->unblessed : undef;
1056
    my $original = C4::Context->preference('HoldsLog') ? $hold->unblessed : undef;
1054
1057
1055
    if ( $rank eq "del" ) {
1058
    if ( $rank eq "del" ) {
1056
        $hold->cancel({ cancellation_reason => $cancellation_reason });
1059
        $hold->cancel({ cancellation_reason => $cancellation_reason, notify_patron => $notify_patron });
1057
    }
1060
    }
1058
    elsif ($hold->found && $hold->priority eq '0' && $date) {
1061
    elsif ($hold->found && $hold->priority eq '0' && $date) {
1059
1062
(-)a/Koha/Hold.pm (-1 / +2 lines)
Lines 695-700 my $cancel_hold = $hold->cancel( Link Here
695
        [ charge_cancel_fee   => 1||0, ]
695
        [ charge_cancel_fee   => 1||0, ]
696
        [ cancellation_reason => $cancellation_reason, ]
696
        [ cancellation_reason => $cancellation_reason, ]
697
        [ skip_holds_queue    => 1||0 ]
697
        [ skip_holds_queue    => 1||0 ]
698
        [ notify_patron       => 1||0, ]
698
    }
699
    }
699
);
700
);
700
701
Lines 738-744 sub cancel { Link Here
738
                }, undef, $self->id
739
                }, undef, $self->id
739
            );
740
            );
740
741
741
            if ( $params->{cancellation_reason} ) {
742
            if ( $params->{notify_patron} ) {
742
                my $letter = C4::Letters::GetPreparedLetter(
743
                my $letter = C4::Letters::GetPreparedLetter(
743
                    module                 => 'reserves',
744
                    module                 => 'reserves',
744
                    letter_code            => 'HOLD_CANCELLATION',
745
                    letter_code            => 'HOLD_CANCELLATION',
(-)a/circ/pendingreserves.pl (-8 / +16 lines)
Lines 55-61 if ( $op eq 'cud-cancel_reserve' and $reserve_id ) { Link Here
55
    my $hold = Koha::Holds->find( $reserve_id );
55
    my $hold = Koha::Holds->find( $reserve_id );
56
    if ( $hold ) {
56
    if ( $hold ) {
57
        my $cancellation_reason = $input->param('cancellation-reason');
57
        my $cancellation_reason = $input->param('cancellation-reason');
58
        $hold->cancel({ cancellation_reason => $cancellation_reason });
58
        my $cancellation_notify_patron = $input->param('cancellation-notify-patron');
59
        $hold->cancel({ cancellation_reason => $cancellation_reason, notify_patron => $cancellation_notify_patron });
59
        push @messages, { type => 'message', code => 'hold_cancelled' };
60
        push @messages, { type => 'message', code => 'hold_cancelled' };
60
    }
61
    }
61
} elsif ( $op =~ m|^mark_as_lost| ) {
62
} elsif ( $op =~ m|^mark_as_lost| ) {
Lines 299-312 foreach my $bibnum ( @biblionumbers ){ Link Here
299
    push @holds_info, $hold_info;
300
    push @holds_info, $hold_info;
300
}
301
}
301
302
303
my $cancel_notify_templates = Koha::Notice::Templates->search({ module => 'reserves', code => 'HOLD_CANCELLATION' });
304
my $cancel_notice_branches;
305
while ( my $notice = $cancel_notify_templates->next ) {
306
    $cancel_notice_branches->{$notice->branchcode} = 1;
307
}
308
302
$template->param(
309
$template->param(
303
    todaysdate          => $today,
310
    cancel_notice_branches => $cancel_notice_branches,
304
    from                => $startdate,
311
    todaysdate             => $today,
305
    to                  => $enddate,
312
    from                   => $startdate,
306
    holds_info          => \@holds_info,
313
    to                     => $enddate,
307
    HoldsToPullStartDate => C4::Context->preference('HoldsToPullStartDate') || PULL_INTERVAL,
314
    holds_info             => \@holds_info,
308
    HoldsToPullEndDate  => C4::Context->preference('ConfirmFutureHolds') || 0,
315
    HoldsToPullStartDate   => C4::Context->preference('HoldsToPullStartDate') || PULL_INTERVAL,
309
    messages            => \@messages,
316
    messages               => \@messages,
317
    HoldsToPullEndDate     => C4::Context->preference('ConfirmFutureHolds') || 0,
310
);
318
);
311
319
312
output_html_with_http_headers $input, $cookie, $template->output;
320
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+14 lines)
Lines 2535-2537 tables: Link Here
2535
            - "Your hold on [% hold.biblio.title %] ([% hold.biblio.id %]) has been confirmed."
2535
            - "Your hold on [% hold.biblio.title %] ([% hold.biblio.id %]) has been confirmed."
2536
            - "You will be notified by the library when your item is available for pickup."
2536
            - "You will be notified by the library when your item is available for pickup."
2537
            - "Thank you!"
2537
            - "Thank you!"
2538
2539
        - module: reserves
2540
          code: HOLD_CANCELLATION
2541
          branchcode: ""
2542
          name: "Notification of hold cancellation"
2543
          is_html: 0
2544
          title: "Your hold was cancelled"
2545
          message_transport_type: email
2546
          lang: default
2547
          content:
2548
            - "[%- USE AuthorisedValues -%]"
2549
            - "Dear [% borrower.firstname %] [% borrower.surname %],"
2550
            - ""
2551
            - "Your hold for [% biblio.title %] was cancelled [% IF hold.cancellation_reason %] for the following reason: [% AuthorisedValues.GetByCode( 'HOLD_CANCELLATION', hold.cancellation_reason ) %][% END %]"
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc (+8 lines)
Lines 93-98 Link Here
93
                        <input type="hidden" name="rank-request" class="rank-request" value="[% hold.priority | html %]" data-hold-id="[% hold.reserve_id | html %]">
93
                        <input type="hidden" name="rank-request" class="rank-request" value="[% hold.priority | html %]" data-hold-id="[% hold.reserve_id | html %]">
94
                        [% hold.priority | html %]
94
                        [% hold.priority | html %]
95
                    [% END %]
95
                    [% END %]
96
97
                    [% IF cancel_notice_branches.size %]
98
                        [% SET bc = hold.patron.branchcode %]
99
                        [% SET all_bc = "" %]
100
                        [% UNLESS cancel_notice_branches.$bc || cancel_notice_branches.$all_bc %]
101
                            <span class="no-notice-warning text-warning">Cancellation will not receive a notice.</span>
102
                        [% END %]
103
                    [% END %]
96
                </td>
104
                </td>
97
                [%- IF ( CAN_user_reserveforothers_modify_holds_priority ) -%]
105
                [%- IF ( CAN_user_reserveforothers_modify_holds_priority ) -%]
98
                [%- UNLESS hold.found -%]
106
                [%- UNLESS hold.found -%]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc (+3 lines)
Lines 175-180 Link Here
175
                                        <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
175
                                        <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
176
                                    [% END %]
176
                                    [% END %]
177
                                </select>
177
                                </select>
178
179
                                <input type="checkbox" name="cancellation-notify-patron" id="cancellation-notify-patron" value="1" checked/>
180
                                <label for="cancellation-notify-patron">Notify patron</label>
178
                            [% END %]
181
                            [% END %]
179
                        </fieldset>
182
                        </fieldset>
180
                    </form>
183
                    </form>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +1 lines)
Lines 916-922 Link Here
916
                    </div> <!-- /div or div.col-sm-6 -->
916
                    </div> <!-- /div or div.col-sm-6 -->
917
                </div> <!-- /.row -->
917
                </div> <!-- /.row -->
918
918
919
                    [% INCLUDE 'patron-detail-tabs.inc' patronpage = "circ" %]
919
                [% INCLUDE 'patron-detail-tabs.inc' patronpage = "circ" %]
920
920
921
                [% ELSIF borrowernumber # IF patron %]
921
                [% ELSIF borrowernumber # IF patron %]
922
                    <div class="alert alert-info">Patron not found. <a href="/cgi-bin/koha/members/members-home.pl">Return to search</a></div>
922
                    <div class="alert alert-info">Patron not found. <a href="/cgi-bin/koha/members/members-home.pl">Return to search</a></div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt (+9 lines)
Lines 220-225 Link Here
220
                                <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
220
                                <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
221
                            [% END %]
221
                            [% END %]
222
                        </select>
222
                        </select>
223
224
                        [% IF cancel_notice_branches.size %]
225
                            [% SET bc = hold.patron.branchcode %]
226
                            [% SET all_bc = "" %]
227
                            [% IF cancel_notice_branches.$bc || cancel_notice_branches.$all_bc %]
228
                                <input type="checkbox" name="cancellation-notify-patron" id="cancellation-notify-patron" value="1" checked/>
229
                                <label for="cancellation-notify-patron">Notify patron</label>
230
                            [% END %]
231
                        [% END %]
223
                    </div>
232
                    </div>
224
                [% END %]
233
                [% END %]
225
234
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-9 / +17 lines)
Lines 1256-1262 Link Here
1256
                            </div>
1256
                            </div>
1257
                        <fieldset id="cancellation-reason-fieldset" class="action" style="display:none">
1257
                        <fieldset id="cancellation-reason-fieldset" class="action" style="display:none">
1258
                            [% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
1258
                            [% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
1259
                            [% IF hold_cancellation.count %]
1259
                            [% IF hold_cancellation.count && cancel_notice_branches.size %]
1260
                                <label for="cancellation-reason">Cancellation reason: </label>
1260
                                <label for="cancellation-reason">Cancellation reason: </label>
1261
                                <select class="cancellation-reason" name="cancellation-reason" id="cancellation-reason">
1261
                                <select class="cancellation-reason" name="cancellation-reason" id="cancellation-reason">
1262
                                    <option value="">No reason given</option>
1262
                                    <option value="">No reason given</option>
Lines 1264-1269 Link Here
1264
                                        <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
1264
                                        <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
1265
                                    [% END %]
1265
                                    [% END %]
1266
                                </select>
1266
                                </select>
1267
1268
                                <input type="checkbox" name="cancellation-notify-patron" id="cancellation-notify-patron" value="1" checked/>
1269
                                <label for="cancellation-notify-patron">Notify patron</label>
1267
                            [% END %]
1270
                            [% END %]
1268
                        </fieldset>
1271
                        </fieldset>
1269
                        </div>
1272
                        </div>
Lines 1304-1310 Link Here
1304
                                                <div class="holds_by_library">
1307
                                                <div class="holds_by_library">
1305
                                                    <h4>[% Branches.GetName( b ) | html %]</h4>
1308
                                                    <h4>[% Branches.GetName( b ) | html %]</h4>
1306
1309
1307
                                                    [% INCLUDE holds_table.inc holds=holds_by_branch %]
1310
                                                    [% INCLUDE holds_table.inc holds=holds_by_branch cancel_notice_branches=cancel_notice_branches %]
1308
                                                </div>
1311
                                                </div>
1309
                                            [% END # /FOREACh b %]
1312
                                            [% END # /FOREACh b %]
1310
                                        [% END # /IF ( branchcodes.empty ) %]
1313
                                        [% END # /IF ( branchcodes.empty ) %]
Lines 1450-1456 Link Here
1450
                        <div id="cancel_hold_alert" class="alert alert-danger" style="display:none;"></div>
1453
                        <div id="cancel_hold_alert" class="alert alert-danger" style="display:none;"></div>
1451
                        <fieldset class="action">
1454
                        <fieldset class="action">
1452
                            [% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
1455
                            [% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
1453
                            [% IF hold_cancellation.count %]
1456
                            [% IF hold_cancellation.count && cancel_notice_branches.size %]
1454
                                <label for="cancellation-reason">Cancellation reason: </label>
1457
                                <label for="cancellation-reason">Cancellation reason: </label>
1455
                                <select class="cancellation-reason" name="cancellation-reason" id="modal-cancellation-reason">
1458
                                <select class="cancellation-reason" name="cancellation-reason" id="modal-cancellation-reason">
1456
                                    <option value="">No reason given</option>
1459
                                    <option value="">No reason given</option>
Lines 1458-1463 Link Here
1458
                                        <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
1461
                                        <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
1459
                                    [% END %]
1462
                                    [% END %]
1460
                                </select>
1463
                                </select>
1464
1465
                                <input type="checkbox" name="cancellation-notify-patron" id="cancellation-notify-patron" value="1" checked>
1466
                                <label for="cancellation-notify-patron">Notify patron</label>
1461
                            [% END %]
1467
                            [% END %]
1462
                        </fieldset>
1468
                        </fieldset>
1463
                    </div>
1469
                    </div>
Lines 1531-1542 Link Here
1531
        $.fn.select2.defaults.set("dropdownAutoWidth", true );
1537
        $.fn.select2.defaults.set("dropdownAutoWidth", true );
1532
1538
1533
        $(document).ready(function() {
1539
        $(document).ready(function() {
1534
            $('#cancellation-reason-fieldset').hide();
1540
            $('#cancellation-reason-fieldset, .no-notice-warning').hide();
1535
            $('.rank-request').on('change', function() {
1541
            $('.rank-request').on('change', function() {
1536
                if ( $(".rank-request option:selected[value='del']").length ) {
1542
                if ( $(".rank-request option:selected[value='del']").length ) {
1537
                    $('#cancellation-reason-fieldset').show();
1543
                    $('#cancellation-reason-fieldset').show();
1544
                    $('.no-notice-warning').show();
1538
                } else {
1545
                } else {
1539
                    $('#cancellation-reason-fieldset').hide();
1546
                    $('#cancellation-reason-fieldset').hide();
1547
                    $('.no-notice-warning').hide();
1540
                }
1548
                }
1541
            });
1549
            });
1542
1550
Lines 1852-1862 Link Here
1852
                e.preventDefault;
1860
                e.preventDefault;
1853
                cancel_link = $(this);
1861
                cancel_link = $(this);
1854
                $("#cancel_modal_form #inputs").empty();
1862
                $("#cancel_modal_form #inputs").empty();
1855
                    let reserve_id = cancel_link.data('id');
1863
                let reserve_id = cancel_link.data('id');
1856
                    let biblionumber = cancel_link.data('biblionumber');
1864
                let biblionumber = cancel_link.data('biblionumber');
1857
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="reserve_id" value="' + reserve_id + '">');
1865
                $("#cancel_modal_form #inputs").append('<input type="hidden" name="reserve_id" value="' + reserve_id + '">');
1858
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="biblionumber" value="' + biblionumber + '">');
1866
                $("#cancel_modal_form #inputs").append('<input type="hidden" name="biblionumber" value="' + biblionumber + '">');
1859
                    $("#cancel_modal_form #inputs").append('<input type="hidden" name="op" value="cud-cancel">');
1867
                $("#cancel_modal_form #inputs").append('<input type="hidden" name="op" value="cud-cancel">');
1860
                $('#cancelModal').modal('show');
1868
                $('#cancelModal').modal('show');
1861
                return false;
1869
                return false;
1862
            });
1870
            });
(-)a/misc/cronjobs/holds/cancel_expired_holds.pl (-5 / +11 lines)
Lines 25-36 cancel_expired_holds.pl - cron script to cancel holds as they expire Link Here
25
=head1 SYNOPSIS
25
=head1 SYNOPSIS
26
26
27
  ./cancel_expired_holds.pl
27
  ./cancel_expired_holds.pl
28
  ./cancel_expired_holds.pl --reason="EXPIRED"
28
  ./cancel_expired_holds.pl --reason="EXPIRED" --notify
29
29
30
or, in crontab:
30
or, in crontab:
31
31
32
  0 1 * * * cancel_expired_holds.pl
32
  0 1 * * * cancel_expired_holds.pl
33
  0 1 * * * cancel_expired_holds.pl --reason="EXPIRED"
33
  0 1 * * * cancel_expired_holds.pl --reason="EXPIRED" --notify
34
34
35
=head1 DESCRIPTION
35
=head1 DESCRIPTION
36
36
Lines 56-80 Print a brief help message and exits. Link Here
56
56
57
=item B<--reason>
57
=item B<--reason>
58
58
59
Optionally adds a reason for cancellation (which will trigger a notice to be sent to the patron)
59
Optionally adds a reason for cancellation
60
61
=item B<--notify>
62
63
Optionally trigger a notice to be sent to the patron
60
64
61
=back
65
=back
62
66
63
=cut
67
=cut
64
68
65
my $help = 0;
69
my $help = 0;
70
my $notify = 0;
66
my $reason;
71
my $reason;
67
72
68
my $command_line_options = join(" ",@ARGV);
73
my $command_line_options = join(" ",@ARGV);
69
74
70
GetOptions(
75
GetOptions(
71
    'help|?'   => \$help,
76
    'help|?'   => \$help,
72
    'reason=s' => \$reason
77
    'notify'   => \$notify,
78
    'reason=s' => \$reason,
73
) or pod2usage(1);
79
) or pod2usage(1);
74
pod2usage(1) if $help;
80
pod2usage(1) if $help;
75
81
76
cronlogaction({ info => $command_line_options });
82
cronlogaction({ info => $command_line_options });
77
83
78
C4::Reserves::CancelExpiredReserves($reason);
84
C4::Reserves::CancelExpiredReserves($reason, $notify);
79
85
80
cronlogaction({ action => 'End', info => "COMPLETED" });
86
cronlogaction({ action => 'End', info => "COMPLETED" });
(-)a/reserve/modrequest.pl (+3 lines)
Lines 56-61 if( $op eq 'cud-cancelall' || $op eq 'cud-modifyall' ) { Link Here
56
        undef $itemnumber[$i] if !$itemnumber[$i];
56
        undef $itemnumber[$i] if !$itemnumber[$i];
57
        my $suspend_until = $query->param( "suspend_until_" . $reserve_id[$i] );
57
        my $suspend_until = $query->param( "suspend_until_" . $reserve_id[$i] );
58
        my $cancellation_reason = $query->param("cancellation-reason");
58
        my $cancellation_reason = $query->param("cancellation-reason");
59
        my $cancellation_notify_patron = $query->param("cancellation-notify-patron");
60
59
        my $params = {
61
        my $params = {
60
            rank => $rank[$i],
62
            rank => $rank[$i],
61
            reserve_id => $reserve_id[$i],
63
            reserve_id => $reserve_id[$i],
Lines 64-69 if( $op eq 'cud-cancelall' || $op eq 'cud-modifyall' ) { Link Here
64
            itemnumber => $itemnumber[$i],
66
            itemnumber => $itemnumber[$i],
65
            defined $suspend_until ? ( suspend_until => $suspend_until ) : (),
67
            defined $suspend_until ? ( suspend_until => $suspend_until ) : (),
66
            cancellation_reason => $cancellation_reason,
68
            cancellation_reason => $cancellation_reason,
69
            notify_patron => $cancellation_notify_patron,
67
        };
70
        };
68
        if (C4::Context->preference('AllowHoldDateInFuture')) {
71
        if (C4::Context->preference('AllowHoldDateInFuture')) {
69
            $params->{reservedate} = $reservedates[$i] || undef;
72
            $params->{reservedate} = $reservedates[$i] || undef;
(-)a/reserve/request.pl (-1 / +12 lines)
Lines 113-120 if ( $op eq 'cud-move' ) { Link Here
113
elsif ( $op eq 'cud-cancel' ) {
113
elsif ( $op eq 'cud-cancel' ) {
114
    my $reserve_id          = $input->param('reserve_id');
114
    my $reserve_id          = $input->param('reserve_id');
115
    my $cancellation_reason = $input->param("cancellation-reason");
115
    my $cancellation_reason = $input->param("cancellation-reason");
116
    my $cancellation_notify_patron = $input->param("cancellation-notify-patron");
116
    my $hold                = Koha::Holds->find($reserve_id);
117
    my $hold                = Koha::Holds->find($reserve_id);
117
    $hold->cancel( { cancellation_reason => $cancellation_reason } ) if $hold;
118
    $hold->cancel( { cancellation_reason => $cancellation_reason, notify_patron => $cancellation_notify_patron } ) if $hold;
118
}
119
}
119
elsif ( $op eq 'cud-setLowestPriority' ) {
120
elsif ( $op eq 'cud-setLowestPriority' ) {
120
    my $reserve_id = $input->param('reserve_id');
121
    my $reserve_id = $input->param('reserve_id');
Lines 725-730 $template->param(borrowernumber => $borrowernumber_hold); Link Here
725
726
726
$template->param( failed_holds => \@failed_holds );
727
$template->param( failed_holds => \@failed_holds );
727
728
729
# Show hold cancellation reason only if notice exists
730
my $cancel_notify_templates = Koha::Notice::Templates->search({ module => 'reserves', code => 'HOLD_CANCELLATION' });
731
my $cancel_notice_branches;
732
while ( my $notice = $cancel_notify_templates->next ) {
733
    $cancel_notice_branches->{$notice->branchcode} = 1;
734
}
735
$template->param(
736
    cancel_notice_branches => $cancel_notice_branches,
737
);
738
728
# printout the page
739
# printout the page
729
output_html_with_http_headers $input, $cookie, $template->output;
740
output_html_with_http_headers $input, $cookie, $template->output;
730
741
(-)a/t/db_dependent/Koha/Hold.t (-2 / +90 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 14;
22
use Test::More tests => 15;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 1089-1091 subtest 'change_type() tests' => sub { Link Here
1089
1089
1090
    $schema->storage->txn_rollback;
1090
    $schema->storage->txn_rollback;
1091
};
1091
};
1092
- 
1092
1093
subtest 'cancel() tests' => sub {
1094
1095
    plan tests => 11;
1096
1097
    $schema->storage->txn_begin;
1098
1099
    my $get_prepared_letter_called;
1100
1101
    # Mock GetPreparedLetter so it raises a warning we can look for
1102
    # and returns undef, so no call to EnqueueLetter happens
1103
    my $mocked_letter = Test::MockModule->new("C4::Letters");
1104
    $mocked_letter->mock( 'GetPreparedLetter', sub {
1105
        $get_prepared_letter_called = 1;
1106
        return;
1107
    });
1108
1109
    my $hold = $builder->build_object(
1110
        {
1111
            class => 'Koha::Holds',
1112
            value => {
1113
                cancellationdate    => undef,
1114
                priority            => 1,
1115
                cancellation_reason => undef,
1116
            }
1117
        }
1118
    );
1119
1120
    # leave this things out of the test
1121
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 0 );
1122
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
1123
1124
    $hold = $builder->build_object(
1125
        {
1126
            class => 'Koha::Holds',
1127
            value => {
1128
                cancellationdate    => undef,
1129
                priority            => 1,
1130
                cancellation_reason => undef,
1131
            }
1132
        }
1133
    );
1134
1135
    $get_prepared_letter_called = 0;
1136
    $hold->cancel({ cancellation_reason => 'Some reason' });
1137
    ok( !$get_prepared_letter_called, 'GetPreparedLetter not called' );
1138
1139
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
1140
    is( $hold->priority, 0, 'priority gets set to 0' );
1141
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
1142
1143
    $hold = $builder->build_object(
1144
        {
1145
            class => 'Koha::Holds',
1146
            value => {
1147
                cancellationdate    => undef,
1148
                priority            => 1,
1149
                cancellation_reason => undef,
1150
            }
1151
        }
1152
    );
1153
1154
    $get_prepared_letter_called = 0;
1155
    $hold->cancel({ cancellation_reason => 'Some reason', notify_patron => 1 });
1156
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron and cancellation_reason passed' );
1157
1158
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
1159
    is( $hold->priority, 0, 'priority gets set to 0' );
1160
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
1161
1162
    $hold = $builder->build_object(
1163
        {
1164
            class => 'Koha::Holds',
1165
            value => {
1166
                cancellationdate    => undef,
1167
                priority            => 1,
1168
                cancellation_reason => undef,
1169
            }
1170
        }
1171
    );
1172
1173
    $get_prepared_letter_called = 0;
1174
    $hold->cancel({ notify_patron => 1 });
1175
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
1176
    is( $hold->priority, 0, 'priority gets set to 0' );
1177
    is( $hold->cancellation_reason, undef, 'cancellation_reason not passed' );
1178
1179
    $schema->storage->txn_rollback;
1180
};

Return to bug 26282