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

(-)a/C4/Circulation.pm (-16 / +22 lines)
Lines 856-867 sub CanBookBeIssued { Link Here
856
                and C4::Context->preference('SwitchOnSiteCheckouts') ) {
856
                and C4::Context->preference('SwitchOnSiteCheckouts') ) {
857
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
857
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
858
        } else {
858
        } else {
859
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
859
            my ($CanBookBeRenewed, $renewerror) = CanBookBeRenewed(
860
                $patron->borrowernumber,
860
                $patron->borrowernumber,
861
                $item_object->itemnumber,
861
                $item_object->itemnumber,
862
            );
862
            );
863
863
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
864
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
864
                if ( $renewerror eq 'onsite_checkout' ) {
865
                if ( $renewerror->[0] eq 'onsite_checkout' ) {
865
                    $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
866
                    $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
866
                }
867
                }
867
                else {
868
                else {
Lines 2724-2731 sub CanBookBeRenewed { Link Here
2724
2725
2725
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2726
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2726
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2727
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2727
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2728
    my @errors;
2728
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2729
    push @errors, 'onsite_checkout' if $issue->onsite_checkout;
2730
    push @errors, 'item_denied_renewal' if _item_denied_renewal({ item => $item });
2729
2731
2730
    my $patron = $issue->patron or return;
2732
    my $patron = $issue->patron or return;
2731
2733
Lines 2747-2753 sub CanBookBeRenewed { Link Here
2747
            }
2749
            }
2748
        );
2750
        );
2749
2751
2750
        return ( 0, "too_many" )
2752
        push @errors, 'too_many'
2751
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2753
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2752
2754
2753
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2755
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
Lines 2757-2771 sub CanBookBeRenewed { Link Here
2757
        my $hasoverdues = $patron->has_overdues;
2759
        my $hasoverdues = $patron->has_overdues;
2758
2760
2759
        if ( $restricted and $restrictionblockrenewing ) {
2761
        if ( $restricted and $restrictionblockrenewing ) {
2760
            return ( 0, 'restriction');
2762
            push @errors, 'restriction';
2761
        } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2763
        } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2762
            return ( 0, 'overdue');
2764
            push @errors, 'overdue';
2763
        }
2765
        }
2764
2766
2765
        if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2767
        if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2766
2768
2767
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2769
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2768
                return ( 0, 'auto_account_expired' );
2770
                push @errors, 'auto_account_expired';
2769
            }
2771
            }
2770
2772
2771
            if ( defined $issuing_rule->{no_auto_renewal_after}
2773
            if ( defined $issuing_rule->{no_auto_renewal_after}
Lines 2778-2791 sub CanBookBeRenewed { Link Here
2778
                );
2780
                );
2779
                my $now = dt_from_string;
2781
                my $now = dt_from_string;
2780
                if ( $now >= $maximum_renewal_date ) {
2782
                if ( $now >= $maximum_renewal_date ) {
2781
                    return ( 0, "auto_too_late" );
2783
                    push @errors, 'auto_too_late';
2782
                }
2784
                }
2783
            }
2785
            }
2784
            if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2786
            if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2785
                          and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2787
                          and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2786
                # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2788
                # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2787
                if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2789
                if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2788
                    return ( 0, "auto_too_late" );
2790
                    push @errors, 'auto_too_late';
2789
                }
2791
                }
2790
            }
2792
            }
2791
2793
Lines 2796-2802 sub CanBookBeRenewed { Link Here
2796
                  ? $patron->account->balance
2798
                  ? $patron->account->balance
2797
                  : $patron->account->outstanding_debits->total_outstanding;
2799
                  : $patron->account->outstanding_debits->total_outstanding;
2798
                if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2800
                if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2799
                    return ( 0, "auto_too_much_oweing" );
2801
                    push @errors, 'auto_too_much_oweing';
2800
                }
2802
                }
2801
            }
2803
            }
2802
        }
2804
        }
Lines 2818-2825 sub CanBookBeRenewed { Link Here
2818
2820
2819
            if ( $soonestrenewal > dt_from_string() )
2821
            if ( $soonestrenewal > dt_from_string() )
2820
            {
2822
            {
2821
                return ( 0, "auto_too_soon" ) if $issue->auto_renew && $patron->autorenew_checkouts;
2823
                push @errors, 'auto_too_soon' if $issue->auto_renew && $patron->autorenew_checkouts;
2822
                return ( 0, "too_soon" );
2824
                use Data::Printer colored => 1; warn p @errors;
2825
                push @errors, 'too_soon';
2823
            }
2826
            }
2824
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2827
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2825
                $auto_renew = 1;
2828
                $auto_renew = 1;
Lines 2833-2839 sub CanBookBeRenewed { Link Here
2833
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2836
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2834
                $auto_renew = 1;
2837
                $auto_renew = 1;
2835
            } else {
2838
            } else {
2836
                return ( 0, "auto_too_soon" );
2839
                warn "auto too soon";
2840
                push @errors, 'auto_too_soon';
2837
            }
2841
            }
2838
        }
2842
        }
2839
    }
2843
    }
Lines 2903-2910 sub CanBookBeRenewed { Link Here
2903
            }
2907
            }
2904
        }
2908
        }
2905
    }
2909
    }
2906
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2910
    push @errors, 'on_reserve' if $resfound;    # '' when no hold was found
2907
    return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed
2911
    push @errors, 'auto_renew' if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed
2912
2913
    return ( 0, \@errors ) if @errors;
2908
2914
2909
    return ( 1, undef );
2915
    return ( 1, undef );
2910
}
2916
}
(-)a/C4/SIP/ILS/Transaction/Renew.pm (+1 lines)
Lines 49-54 sub do_renew_for { Link Here
49
        $self->{due} = $self->duedatefromissue($issue, $self->{item}->{itemnumber});
49
        $self->{due} = $self->duedatefromissue($issue, $self->{item}->{itemnumber});
50
        $self->renewal_ok(1);
50
        $self->renewal_ok(1);
51
    } else {
51
    } else {
52
        $renewerror = $renewerror->[0];
52
        $renewerror=~s/on_reserve/Item unavailable due to outstanding holds/;
53
        $renewerror=~s/on_reserve/Item unavailable due to outstanding holds/;
53
        $renewerror=~s/too_many/Item has reached maximum renewals/;
54
        $renewerror=~s/too_many/Item has reached maximum renewals/;
54
        $renewerror=~s/item_denied_renewal/Item renewal is not allowed/;
55
        $renewerror=~s/item_denied_renewal/Item renewal is not allowed/;
(-)a/Koha/Account/Line.pm (+1 lines)
Lines 839-844 sub renew_item { Link Here
839
        $borrowernumber,
839
        $borrowernumber,
840
        $itemnumber
840
        $itemnumber
841
    );
841
    );
842
    $error = $error->[0] if @$error;
842
    if ( $can_renew ) {
843
    if ( $can_renew ) {
843
        my $due_date = C4::Circulation::AddRenewal(
844
        my $due_date = C4::Circulation::AddRenewal(
844
            $borrowernumber,
845
            $borrowernumber,
(-)a/Koha/REST/V1/Checkouts.pm (-1 / +3 lines)
Lines 165-171 sub renew { Link Here
165
        if (!$can_renew) {
165
        if (!$can_renew) {
166
            return $c->render(
166
            return $c->render(
167
                status => 403,
167
                status => 403,
168
                openapi => { error => "Renewal not authorized ($error)" }
168
                openapi => { error => sprintf("Renewal not authorized (%s)", $error->[0]) }
169
            );
169
            );
170
        }
170
        }
171
171
Lines 206-211 sub allows_renewal { Link Here
206
        my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
206
        my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
207
            $checkout->borrowernumber, $checkout->itemnumber);
207
            $checkout->borrowernumber, $checkout->itemnumber);
208
208
209
        $error = $error->[0] if @$error;
210
209
        my $renewable = Mojo::JSON->false;
211
        my $renewable = Mojo::JSON->false;
210
        $renewable = Mojo::JSON->true if $can_renew;
212
        $renewable = Mojo::JSON->true if $can_renew;
211
213
(-)a/circ/renew.pl (+1 lines)
Lines 71-76 if ($barcode) { Link Here
71
                  CanBookBeRenewed( $borrower->borrowernumber(),
71
                  CanBookBeRenewed( $borrower->borrowernumber(),
72
                    $item->itemnumber(), $override_limit );
72
                    $item->itemnumber(), $override_limit );
73
73
74
                $error = $error->[0] if @$error;
74
                if ( $error && ($error eq 'on_reserve') ) {
75
                if ( $error && ($error eq 'on_reserve') ) {
75
                    if ($override_holds) {
76
                    if ($override_holds) {
76
                        $can_renew = 1;
77
                        $can_renew = 1;
(-)a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js (-88 / +97 lines)
Lines 419-516 $(document).ready(function() { Link Here
419
419
420
                        if ( oObj.can_renew ) {
420
                        if ( oObj.can_renew ) {
421
                            // Do nothing
421
                            // Do nothing
422
                        } else if ( oObj.can_renew_error == "on_reserve" ) {
423
                            msg += "<span>"
424
                                    + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
425
                                    + "</span>";
426
427
                            span_style = "display: none";
428
                            span_class = "renewals-allowed-on_reserve";
429
                        } else if ( oObj.can_renew_error == "too_many" ) {
430
                            msg += "<span class='renewals-disabled'>"
431
                                    + NOT_RENEWABLE
432
                                    + "</span>";
433
434
                            span_style = "display: none";
435
                            span_class = "renewals-allowed";
436
                        } else if ( oObj.can_renew_error == "restriction" ) {
437
                            msg += "<span class='renewals-disabled'>"
438
                                    + NOT_RENEWABLE_RESTRICTION
439
                                    + "</span>";
440
441
                            span_style = "display: none";
442
                            span_class = "renewals-allowed";
443
                        } else if ( oObj.can_renew_error == "overdue" ) {
444
                            msg += "<span class='renewals-disabled'>"
445
                                    + NOT_RENEWABLE_OVERDUE
446
                                    + "</span>";
447
448
                            span_style = "display: none";
449
                            span_class = "renewals-allowed";
450
                        } else if ( oObj.can_renew_error == "too_soon" ) {
451
                            msg += "<span class='renewals-disabled'>"
452
                                    + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
453
                                    + "</span>";
454
455
                            span_style = "display: none";
456
                            span_class = "renewals-allowed";
457
                        } else if ( oObj.can_renew_error == "auto_too_soon" ) {
458
                            msg += "<span class='renewals-disabled'>"
459
                                    + NOT_RENEWABLE_AUTO_TOO_SOON
460
                                    + "</span>";
461
462
                            span_style = "display: none";
463
                            span_class = "renewals-allowed";
464
                        } else if ( oObj.can_renew_error == "auto_too_late" ) {
465
                            msg += "<span class='renewals-disabled'>"
466
                                    + NOT_RENEWABLE_AUTO_TOO_LATE
467
                                    + "</span>";
468
469
                            span_style = "display: none";
470
                            span_class = "renewals-allowed";
471
                        } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
472
                            msg += "<span class='renewals-disabled'>"
473
                                    + NOT_RENEWABLE_AUTO_TOO_MUCH_OWEING
474
                                    + "</span>";
475
476
                            span_style = "display: none";
477
                            span_class = "renewals-allowed";
478
                        } else if ( oObj.can_renew_error == "auto_account_expired" ) {
479
                            msg += "<span class='renewals-disabled'>"
480
                                    + NOT_RENEWABLE_AUTO_ACCOUNT_EXPIRED
481
                                    + "</span>";
482
483
                            span_style = "display: none";
484
                            span_class = "renewals-allowed";
485
                        } else if ( oObj.can_renew_error == "auto_renew" ) {
486
                            msg += "<span class='renewals-disabled'>"
487
                                    + NOT_RENEWABLE_AUTO_RENEW
488
                                    + "</span>";
489
490
                            span_style = "display: none";
491
                            span_class = "renewals-allowed";
492
                        } else if ( oObj.can_renew_error == "onsite_checkout" ) {
493
                            // Don't display something if it's an onsite checkout
494
                        } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
495
                            content += "<span class='renewals-disabled'>"
496
                                    + NOT_RENEWABLE_DENIED
497
                                    + "</span>";
498
499
                            span_style = "display: none";
500
                            span_class = "renewals-allowed";
501
                        } else {
422
                        } else {
502
                            msg += "<span class='renewals-disabled'>"
423
                            $(oObj.can_renew_error).each(function(i, error){
503
                                    + oObj.can_renew_error
424
                                if ( error == "on_reserve" ) {
504
                                    + "</span>";
425
                                    msg += "<span>"
426
                                            + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
427
                                            + "</span>";
428
429
                                    span_style = "display: none";
430
                                    span_class = "renewals-allowed-on_reserve";
431
                                }
432
                                if ( error == "too_many" ) {
433
                                    msg += "<span class='renewals-disabled'>"
434
                                            + NOT_RENEWABLE
435
                                            + "</span>";
436
437
                                    span_style = "display: none";
438
                                    span_class = "renewals-allowed";
439
                                }
440
                                if ( error == "restriction" ) {
441
                                    msg += "<span class='renewals-disabled'>"
442
                                            + NOT_RENEWABLE_RESTRICTION
443
                                            + "</span>";
444
445
                                    span_style = "display: none";
446
                                    span_class = "renewals-allowed";
447
                                }
448
                                if ( error == "overdue" ) {
449
                                    msg += "<span class='renewals-disabled'>"
450
                                            + NOT_RENEWABLE_OVERDUE
451
                                            + "</span>";
452
453
                                    span_style = "display: none";
454
                                    span_class = "renewals-allowed";
455
                                }
456
                                if ( error == "too_soon" ) {
457
                                    msg += "<span class='renewals-disabled'>"
458
                                            + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
459
                                            + "</span>";
460
461
                                    span_style = "display: none";
462
                                    span_class = "renewals-allowed";
463
                                }
464
                                if ( error == "auto_too_soon" ) {
465
                                    msg += "<span class='renewals-disabled'>"
466
                                            + NOT_RENEWABLE_AUTO_TOO_SOON
467
                                            + "</span>";
468
469
                                    span_style = "display: none";
470
                                    span_class = "renewals-allowed";
471
                                }
472
                                if ( error == "auto_too_late" ) {
473
                                    msg += "<span class='renewals-disabled'>"
474
                                            + NOT_RENEWABLE_AUTO_TOO_LATE
475
                                            + "</span>";
505
476
506
                            span_style = "display: none";
477
                                    span_style = "display: none";
507
                            span_class = "renewals-allowed";
478
                                    span_class = "renewals-allowed";
479
                                }
480
                                if ( error == "auto_too_much_oweing" ) {
481
                                    msg += "<span class='renewals-disabled'>"
482
                                            + NOT_RENEWABLE_AUTO_TOO_MUCH_OWEING
483
                                            + "</span>";
484
485
                                    span_style = "display: none";
486
                                    span_class = "renewals-allowed";
487
                                }
488
                                if ( error == "auto_account_expired" ) {
489
                                    msg += "<span class='renewals-disabled'>"
490
                                            + NOT_RENEWABLE_AUTO_ACCOUNT_EXPIRED
491
                                            + "</span>";
492
493
                                    span_style = "display: none";
494
                                    span_class = "renewals-allowed";
495
                                }
496
                                if ( error == "auto_renew" ) {
497
                                    msg += "<span class='renewals-disabled'>"
498
                                            + NOT_RENEWABLE_AUTO_RENEW
499
                                            + "</span>";
500
501
                                    span_style = "display: none";
502
                                    span_class = "renewals-allowed";
503
                                }
504
                                if ( error == "onsite_checkout" ) {
505
                                    // Don't display something if it's an onsite checkout
506
                                }
507
                                if ( error == "item_denied_renewal" ) {
508
                                    content += "<span class='renewals-disabled'>"
509
                                            + NOT_RENEWABLE_DENIED
510
                                            + "</span>";
511
512
                                    span_style = "display: none";
513
                                    span_class = "renewals-allowed";
514
                                }
515
                                msg += "<br/>";
516
                            });
508
                        }
517
                        }
509
518
510
                        var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
519
                        var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
511
                            ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
520
                            ( !oObj.can_renew_error.includes("on_reserve") || (oObj.can_renew_error.includes("on_reserve") && AllowRenewalOnHoldOverride))
512
                            ? true : false;
521
                            ? true : false;
513
                        var can_renew = ( oObj.renewals_remaining > 0  && !oObj.can_renew_error );
522
                        var can_renew = ( oObj.renewals_remaining > 0  && !oObj.can_renew_error.length );
514
                        content += "<span>";
523
                        content += "<span>";
515
                        if ( can_renew || can_force_renew ) {
524
                        if ( can_renew || can_force_renew ) {
516
                            content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
525
                            content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
Lines 519-525 $(document).ready(function() { Link Here
519
                            if ( oObj.date_due_overdue && can_renew ) {
528
                            if ( oObj.date_due_overdue && can_renew ) {
520
                                content += "checked='checked' ";
529
                                content += "checked='checked' ";
521
                            }
530
                            }
522
                            if (oObj.can_renew_error == "on_reserve") {
531
                            if (oObj.can_renew_error.includes("on_reserve")) {
523
                                content += "data-on-reserve ";
532
                                content += "data-on-reserve ";
524
                            }
533
                            }
525
                            content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
534
                            content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
Lines 541-547 $(document).ready(function() { Link Here
541
                    "bSortable": false,
550
                    "bSortable": false,
542
                    "bVisible": AllowCirculate ? true : false,
551
                    "bVisible": AllowCirculate ? true : false,
543
                    "mDataProp": function ( oObj ) {
552
                    "mDataProp": function ( oObj ) {
544
                        if ( oObj.can_renew_error == "on_reserve" ) {
553
                        if ( oObj.can_renew_error.includes("on_reserve") ) {
545
                            return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
554
                            return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
546
                        } else {
555
                        } else {
547
                            return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
556
                            return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
(-)a/misc/cronjobs/automatic_renewals.pl (+1 lines)
Lines 89-94 while ( my $auto_renew = $auto_renews->next ) { Link Here
89
89
90
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
90
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
91
    my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber );
91
    my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber );
92
    $error = $error->[0] if @$error;
92
    if ( $error eq 'auto_renew' ) {
93
    if ( $error eq 'auto_renew' ) {
93
        if ($verbose) {
94
        if ($verbose) {
94
            say sprintf "Issue id: %s for borrower: %s and item: %s ". ( $confirm ? 'will' : 'would') . " be renewed.",
95
            say sprintf "Issue id: %s for borrower: %s and item: %s ". ( $confirm ? 'will' : 'would') . " be renewed.",
(-)a/opac/opac-renew.pl (+1 lines)
Lines 62-67 else { Link Here
62
    for my $itemnumber (@items) {
62
    for my $itemnumber (@items) {
63
        my ( $status, $error ) =
63
        my ( $status, $error ) =
64
          CanBookBeRenewed( $borrowernumber, $itemnumber );
64
          CanBookBeRenewed( $borrowernumber, $itemnumber );
65
        $error = $error->[0] if @$error;
65
        if ( $status == 1 && $opacrenew == 1 ) {
66
        if ( $status == 1 && $opacrenew == 1 ) {
66
            AddRenewal( $borrowernumber, $itemnumber, undef, undef, undef );
67
            AddRenewal( $borrowernumber, $itemnumber, undef, undef, undef );
67
            push( @renewed, $itemnumber );
68
            push( @renewed, $itemnumber );
(-)a/opac/opac-user.pl (-1 / +2 lines)
Lines 232-238 if ( $pending_checkouts->count ) { # Useless test Link Here
232
232
233
        $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
233
        $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
234
234
235
        if ($renewerror) {
235
        if (@$renewerror) {
236
            $renewerror = $renewerror->[0];
236
            $issue->{'too_many'}       = 1 if $renewerror eq 'too_many';
237
            $issue->{'too_many'}       = 1 if $renewerror eq 'too_many';
237
            $issue->{'on_reserve'}     = 1 if $renewerror eq 'on_reserve';
238
            $issue->{'on_reserve'}     = 1 if $renewerror eq 'on_reserve';
238
            $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
239
            $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
(-)a/opac/sco/sco-main.pl (+1 lines)
Lines 273-278 if ($borrower) { Link Here
273
            $borrower->{borrowernumber},
273
            $borrower->{borrowernumber},
274
            $checkout->{itemnumber},
274
            $checkout->{itemnumber},
275
        );
275
        );
276
        $renew_error = $renew_error->[0] if @$renew_error;
276
        $checkout->{can_be_renewed} = $can_be_renewed; # In the future this will be $checkout->can_be_renewed
277
        $checkout->{can_be_renewed} = $can_be_renewed; # In the future this will be $checkout->can_be_renewed
277
        $checkout->{renew_error} = $renew_error;
278
        $checkout->{renew_error} = $renew_error;
278
        $checkout->{overdue} = $c->is_overdue;
279
        $checkout->{overdue} = $c->is_overdue;
(-)a/svc/checkouts (-1 / +1 lines)
Lines 149-155 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
149
    my ( $can_renew, $can_renew_error ) =
149
    my ( $can_renew, $can_renew_error ) =
150
      CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} );
150
      CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} );
151
    my $can_renew_date =
151
    my $can_renew_date =
152
      $can_renew_error && $can_renew_error eq 'too_soon'
152
      @$can_renew_error && $can_renew_error->[0] eq 'too_soon'
153
      ? output_pref(
153
      ? output_pref(
154
        {
154
        {
155
            dt => GetSoonestRenewDate( $c->{borrowernumber}, $c->{itemnumber} ),
155
            dt => GetSoonestRenewDate( $c->{borrowernumber}, $c->{itemnumber} ),
(-)a/t/db_dependent/Circulation.t (-34 / +33 lines)
Lines 448-458 subtest "CanBookBeRenewed tests" => sub { Link Here
448
448
449
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
449
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
450
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
450
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
451
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
451
    is( $error->[0], 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
452
452
453
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber);
453
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber);
454
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
454
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
455
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
455
    is( $error->[0], 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
456
456
457
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
457
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
458
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
458
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
Lines 481-487 subtest "CanBookBeRenewed tests" => sub { Link Here
481
481
482
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
482
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
483
    is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved');
483
    is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved');
484
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)');
484
    is( $error->[0], 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)');
485
485
486
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber, 1);
486
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber, 1);
487
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
487
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
Lines 625-631 subtest "CanBookBeRenewed tests" => sub { Link Here
625
    ( $renewokay, $error ) =
625
    ( $renewokay, $error ) =
626
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
626
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
627
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
627
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
628
    is( $error, 'auto_too_soon',
628
    is( $error->[0], 'auto_too_soon',
629
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
629
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
630
    AddReserve(
630
    AddReserve(
631
        {
631
        {
Lines 644-657 subtest "CanBookBeRenewed tests" => sub { Link Here
644
    );
644
    );
645
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
645
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
646
    is( $renewokay, 0, 'Still should not be able to renew' );
646
    is( $renewokay, 0, 'Still should not be able to renew' );
647
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked' );
647
    is( $error->[0], 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked' );
648
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
648
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
649
    is( $renewokay, 0, 'Still should not be able to renew' );
649
    is( $renewokay, 0, 'Still should not be able to renew' );
650
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
650
    is( $error->[0], 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
651
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
651
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
652
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
652
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
653
    is( $renewokay, 0, 'Still should not be able to renew' );
653
    is( $renewokay, 0, 'Still should not be able to renew' );
654
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
654
    is( $error->[0], 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
655
    ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber);
655
    ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber);
656
656
657
657
Lines 676-682 subtest "CanBookBeRenewed tests" => sub { Link Here
676
676
677
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
677
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
678
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
678
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
679
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
679
    is( $error->[0], 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
680
680
681
    # Bug 14395
681
    # Bug 14395
682
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
682
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
Lines 701-714 subtest "CanBookBeRenewed tests" => sub { Link Here
701
    ( $renewokay, $error ) =
701
    ( $renewokay, $error ) =
702
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
702
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
703
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
703
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
704
    is( $error, 'auto_too_soon',
704
    is( $error->[0], 'auto_too_soon',
705
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
705
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
706
    );
706
    );
707
707
708
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
708
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
709
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
709
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
710
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
710
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
711
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
711
    is( $error->[0], 'too_soon', 'Error is too_soon, no auto' );
712
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
712
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
713
713
714
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
714
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
Lines 717-730 subtest "CanBookBeRenewed tests" => sub { Link Here
717
    ( $renewokay, $error ) =
717
    ( $renewokay, $error ) =
718
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
718
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
719
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
719
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
720
    is( $error, 'auto_too_soon',
720
    is( $error->[0], 'auto_too_soon',
721
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
721
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
722
    );
722
    );
723
723
724
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
724
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
725
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
725
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
726
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
726
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
727
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
727
    is( $error->[0], 'too_soon', 'Error is too_soon, no auto' );
728
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
728
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
729
729
730
    # Change policy so that loans can be renewed 99 days prior to the due date
730
    # Change policy so that loans can be renewed 99 days prior to the due date
Lines 733-739 subtest "CanBookBeRenewed tests" => sub { Link Here
733
    ( $renewokay, $error ) =
733
    ( $renewokay, $error ) =
734
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
734
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
735
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
735
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
736
    is( $error, 'auto_renew',
736
    is( $error->[0], 'auto_renew',
737
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
737
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
738
    );
738
    );
739
739
Lines 772-778 subtest "CanBookBeRenewed tests" => sub { Link Here
772
        ( $renewokay, $error ) =
772
        ( $renewokay, $error ) =
773
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
773
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
774
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
774
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
775
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
775
        is( $error->[0], 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
776
776
777
        Koha::CirculationRules->set_rules(
777
        Koha::CirculationRules->set_rules(
778
            {
778
            {
Lines 788-794 subtest "CanBookBeRenewed tests" => sub { Link Here
788
        ( $renewokay, $error ) =
788
        ( $renewokay, $error ) =
789
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
789
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
790
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
790
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
791
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
791
        is( $error->[0], 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
792
792
793
        Koha::CirculationRules->set_rules(
793
        Koha::CirculationRules->set_rules(
794
            {
794
            {
Lines 804-810 subtest "CanBookBeRenewed tests" => sub { Link Here
804
        ( $renewokay, $error ) =
804
        ( $renewokay, $error ) =
805
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
805
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
806
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
806
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
807
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
807
        is( $error->[0], 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
808
808
809
        Koha::CirculationRules->set_rules(
809
        Koha::CirculationRules->set_rules(
810
            {
810
            {
Lines 820-826 subtest "CanBookBeRenewed tests" => sub { Link Here
820
        ( $renewokay, $error ) =
820
        ( $renewokay, $error ) =
821
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
821
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
822
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
822
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
823
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
823
        is( $error->[0],     'auto_renew', 'Cannot renew, renew is automatic' );
824
824
825
        Koha::CirculationRules->set_rules(
825
        Koha::CirculationRules->set_rules(
826
            {
826
            {
Lines 837-843 subtest "CanBookBeRenewed tests" => sub { Link Here
837
        ( $renewokay, $error ) =
837
        ( $renewokay, $error ) =
838
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
838
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
839
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
839
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
840
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
840
        is( $error->[0], 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
841
841
842
        Koha::CirculationRules->set_rules(
842
        Koha::CirculationRules->set_rules(
843
            {
843
            {
Lines 854-860 subtest "CanBookBeRenewed tests" => sub { Link Here
854
        ( $renewokay, $error ) =
854
        ( $renewokay, $error ) =
855
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
855
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
856
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
856
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
857
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
857
        is( $error->[0], 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
858
858
859
        Koha::CirculationRules->set_rules(
859
        Koha::CirculationRules->set_rules(
860
            {
860
            {
Lines 871-877 subtest "CanBookBeRenewed tests" => sub { Link Here
871
        ( $renewokay, $error ) =
871
        ( $renewokay, $error ) =
872
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
872
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
873
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
873
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
874
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
874
        is( $error->[0], 'auto_renew', 'Cannot renew, renew is automatic' );
875
    };
875
    };
876
876
877
    subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew & OPACFineNoRenewalsIncludeCredit" => sub {
877
    subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew & OPACFineNoRenewalsIncludeCredit" => sub {
Lines 917-923 subtest "CanBookBeRenewed tests" => sub { Link Here
917
        ( $renewokay, $error ) =
917
        ( $renewokay, $error ) =
918
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
918
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
919
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
919
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
920
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
920
        is( $error->[0], 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
921
921
922
        $account->add_debit(
922
        $account->add_debit(
923
            {
923
            {
Lines 931-937 subtest "CanBookBeRenewed tests" => sub { Link Here
931
        ( $renewokay, $error ) =
931
        ( $renewokay, $error ) =
932
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
932
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
933
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
933
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
934
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
934
        is( $error->[0], 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
935
935
936
        $account->add_debit(
936
        $account->add_debit(
937
            {
937
            {
Lines 945-951 subtest "CanBookBeRenewed tests" => sub { Link Here
945
        ( $renewokay, $error ) =
945
        ( $renewokay, $error ) =
946
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
946
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
947
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
947
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
948
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
948
        is( $error->[0], 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
949
949
950
        $account->add_credit(
950
        $account->add_credit(
951
            {
951
            {
Lines 958-970 subtest "CanBookBeRenewed tests" => sub { Link Here
958
        ( $renewokay, $error ) =
958
        ( $renewokay, $error ) =
959
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
959
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
960
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
960
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
961
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
961
        is( $error->[0], 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
962
962
963
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
963
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
964
        ( $renewokay, $error ) =
964
        ( $renewokay, $error ) =
965
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
965
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
966
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
966
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
967
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
967
        is( $error->[0], 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
968
968
969
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
969
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
970
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1');
970
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1');
Lines 1004-1010 subtest "CanBookBeRenewed tests" => sub { Link Here
1004
        ( $renewokay, $error ) =
1004
        ( $renewokay, $error ) =
1005
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1005
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1006
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1006
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1007
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1007
        is( $error->[0], 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1008
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1008
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1009
1009
1010
1010
Lines 1016-1022 subtest "CanBookBeRenewed tests" => sub { Link Here
1016
        ( $renewokay, $error ) =
1016
        ( $renewokay, $error ) =
1017
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1017
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1018
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1018
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1019
        is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
1019
        is( $error->[0], 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
1020
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1020
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1021
1021
1022
1022
Lines 1028-1034 subtest "CanBookBeRenewed tests" => sub { Link Here
1028
        ( $renewokay, $error ) =
1028
        ( $renewokay, $error ) =
1029
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1029
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1030
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1030
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1031
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1031
        is( $error->[0], 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1032
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1032
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1033
    };
1033
    };
1034
1034
Lines 1154-1160 subtest "CanBookBeRenewed tests" => sub { Link Here
1154
1154
1155
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1155
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1156
    is( $renewokay, 0, 'Cannot renew, 0 renewals allowed');
1156
    is( $renewokay, 0, 'Cannot renew, 0 renewals allowed');
1157
    is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1157
    is( $error->[0], 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1158
1158
1159
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1159
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1160
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
1160
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
Lines 1543-1549 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1543
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1543
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1544
    my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $item->itemnumber );
1544
    my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $item->itemnumber );
1545
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1545
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1546
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1546
    is( $error->[0], 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1547
}
1547
}
1548
1548
1549
{
1549
{
Lines 3236-3242 subtest 'ItemsDeniedRenewal preference' => sub { Link Here
3236
    ( $idr_mayrenew, $idr_error ) =
3236
    ( $idr_mayrenew, $idr_error ) =
3237
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3237
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3238
    is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' );
3238
    is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' );
3239
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' );
3239
    is( $idr_error->[0], 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' );
3240
    ( $idr_mayrenew, $idr_error ) =
3240
    ( $idr_mayrenew, $idr_error ) =
3241
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3241
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3242
    is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' );
3242
    is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' );
Lines 3248-3254 subtest 'ItemsDeniedRenewal preference' => sub { Link Here
3248
    ( $idr_mayrenew, $idr_error ) =
3248
    ( $idr_mayrenew, $idr_error ) =
3249
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3249
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3250
    is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' );
3250
    is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' );
3251
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' );
3251
    is( $idr_error->[0], 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' );
3252
    ( $idr_mayrenew, $idr_error ) =
3252
    ( $idr_mayrenew, $idr_error ) =
3253
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3253
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3254
    is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
3254
    is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
Lines 3260-3266 subtest 'ItemsDeniedRenewal preference' => sub { Link Here
3260
    ( $idr_mayrenew, $idr_error ) =
3260
    ( $idr_mayrenew, $idr_error ) =
3261
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3261
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3262
    is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
3262
    is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
3263
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' );
3263
    is( $idr_error->[0], 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' );
3264
    ( $idr_mayrenew, $idr_error ) =
3264
    ( $idr_mayrenew, $idr_error ) =
3265
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3265
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3266
    is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
3266
    is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
3267
- 

Return to bug 25758