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

(-)a/C4/Circulation.pm (-16 / +20 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 2760-2767 sub CanBookBeRenewed { Link Here
2760
2761
2761
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2762
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2762
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2763
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2763
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2764
    my @errors;
2764
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2765
    push @errors, 'onsite_checkout' if $issue->onsite_checkout;
2766
    push @errors, 'item_denied_renewal' if _item_denied_renewal({ item => $item });
2765
2767
2766
    my $patron = $issue->patron or return;
2768
    my $patron = $issue->patron or return;
2767
2769
Lines 2783-2789 sub CanBookBeRenewed { Link Here
2783
            }
2785
            }
2784
        );
2786
        );
2785
2787
2786
        return ( 0, "too_many" )
2788
        push @errors, 'too_many'
2787
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2789
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2788
2790
2789
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2791
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
Lines 2793-2807 sub CanBookBeRenewed { Link Here
2793
        my $hasoverdues = $patron->has_overdues;
2795
        my $hasoverdues = $patron->has_overdues;
2794
2796
2795
        if ( $restricted and $restrictionblockrenewing ) {
2797
        if ( $restricted and $restrictionblockrenewing ) {
2796
            return ( 0, 'restriction');
2798
            push @errors, 'restriction';
2797
        } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2799
        } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2798
            return ( 0, 'overdue');
2800
            push @errors, 'overdue';
2799
        }
2801
        }
2800
2802
2801
        if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2803
        if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2802
2804
2803
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2805
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2804
                return ( 0, 'auto_account_expired' );
2806
                push @errors, 'auto_account_expired';
2805
            }
2807
            }
2806
2808
2807
            if ( defined $issuing_rule->{no_auto_renewal_after}
2809
            if ( defined $issuing_rule->{no_auto_renewal_after}
Lines 2814-2827 sub CanBookBeRenewed { Link Here
2814
                );
2816
                );
2815
                my $now = dt_from_string;
2817
                my $now = dt_from_string;
2816
                if ( $now >= $maximum_renewal_date ) {
2818
                if ( $now >= $maximum_renewal_date ) {
2817
                    return ( 0, "auto_too_late" );
2819
                    push @errors, 'auto_too_late';
2818
                }
2820
                }
2819
            }
2821
            }
2820
            if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2822
            if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2821
                          and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2823
                          and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2822
                # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2824
                # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2823
                if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2825
                if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2824
                    return ( 0, "auto_too_late" );
2826
                    push @errors, 'auto_too_late';
2825
                }
2827
                }
2826
            }
2828
            }
2827
2829
Lines 2832-2838 sub CanBookBeRenewed { Link Here
2832
                  ? $patron->account->balance
2834
                  ? $patron->account->balance
2833
                  : $patron->account->outstanding_debits->total_outstanding;
2835
                  : $patron->account->outstanding_debits->total_outstanding;
2834
                if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2836
                if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2835
                    return ( 0, "auto_too_much_oweing" );
2837
                    push @errors, 'auto_too_much_oweing';
2836
                }
2838
                }
2837
            }
2839
            }
2838
        }
2840
        }
Lines 2854-2861 sub CanBookBeRenewed { Link Here
2854
2856
2855
            if ( $soonestrenewal > dt_from_string() )
2857
            if ( $soonestrenewal > dt_from_string() )
2856
            {
2858
            {
2857
                return ( 0, "auto_too_soon" ) if $issue->auto_renew && $patron->autorenew_checkouts;
2859
                push @errors, 'auto_too_soon' if $issue->auto_renew && $patron->autorenew_checkouts;
2858
                return ( 0, "too_soon" );
2860
                push @errors, 'too_soon';
2859
            }
2861
            }
2860
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2862
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2861
                $auto_renew = 1;
2863
                $auto_renew = 1;
Lines 2869-2875 sub CanBookBeRenewed { Link Here
2869
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2871
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2870
                $auto_renew = 1;
2872
                $auto_renew = 1;
2871
            } else {
2873
            } else {
2872
                return ( 0, "auto_too_soon" );
2874
                push @errors, 'auto_too_soon';
2873
            }
2875
            }
2874
        }
2876
        }
2875
    }
2877
    }
Lines 2939-2946 sub CanBookBeRenewed { Link Here
2939
            }
2941
            }
2940
        }
2942
        }
2941
    }
2943
    }
2942
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2944
    push @errors, 'on_reserve' if $resfound;    # '' when no hold was found
2943
    return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed
2945
    push @errors, 'auto_renew' if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed
2946
2947
    return ( 0, \@errors ) if @errors;
2944
2948
2945
    return ( 1, undef );
2949
    return ( 1, undef );
2946
}
2950
}
(-)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 852-857 sub renew_item { Link Here
852
        $borrowernumber,
852
        $borrowernumber,
853
        $itemnumber
853
        $itemnumber
854
    );
854
    );
855
    $error = $error->[0] if @$error;
855
    if ( $can_renew ) {
856
    if ( $can_renew ) {
856
        my $due_date = C4::Circulation::AddRenewal(
857
        my $due_date = C4::Circulation::AddRenewal(
857
            $borrowernumber,
858
            $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 || !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 || !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 && 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 && 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 (-9 / +12 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use CGI;
22
use CGI;
23
use JSON qw(to_json);
23
use JSON qw(to_json);
24
use List::MoreUtils qw( uniq );
24
25
25
use C4::Auth qw(check_cookie_auth haspermission get_session);
26
use C4::Auth qw(check_cookie_auth haspermission get_session);
26
use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
27
use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
Lines 148-162 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
148
149
149
    my ( $can_renew, $can_renew_error ) =
150
    my ( $can_renew, $can_renew_error ) =
150
      CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} );
151
      CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} );
151
    my $can_renew_date =
152
152
      $can_renew_error && $can_renew_error eq 'too_soon'
153
    my $can_renew_date;
153
      ? output_pref(
154
    $can_renew_error &&= [uniq @$can_renew_error];
154
        {
155
    if ( $can_renew_error && grep { $_ eq 'too_soon' } @$can_renew_error ) {
155
            dt => GetSoonestRenewDate( $c->{borrowernumber}, $c->{itemnumber} ),
156
        $can_renew_date = output_pref(
156
            as_due_date => 1
157
            {
157
        }
158
                dt => GetSoonestRenewDate( $c->{borrowernumber}, $c->{itemnumber} ),
158
      )
159
                as_due_date => 1
159
      : undef;
160
            }
161
        );
162
    }
160
163
161
    my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
164
    my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
162
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
165
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
(-)a/t/db_dependent/Circulation.t (-34 / +33 lines)
Lines 452-462 subtest "CanBookBeRenewed tests" => sub { Link Here
452
452
453
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
453
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->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
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber);
457
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber);
458
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
458
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
459
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
459
    is( $error->[0], 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
460
460
461
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
461
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
462
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
462
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
Lines 485-491 subtest "CanBookBeRenewed tests" => sub { Link Here
485
485
486
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
486
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
487
    is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved');
487
    is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved');
488
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)');
488
    is( $error->[0], 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)');
489
489
490
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber, 1);
490
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber, 1);
491
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
491
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
Lines 629-635 subtest "CanBookBeRenewed tests" => sub { Link Here
629
    ( $renewokay, $error ) =
629
    ( $renewokay, $error ) =
630
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
630
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
631
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
631
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
632
    is( $error, 'auto_too_soon',
632
    is( $error->[0], 'auto_too_soon',
633
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
633
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
634
    AddReserve(
634
    AddReserve(
635
        {
635
        {
Lines 648-661 subtest "CanBookBeRenewed tests" => sub { Link Here
648
    );
648
    );
649
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
649
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
650
    is( $renewokay, 0, 'Still should not be able to renew' );
650
    is( $renewokay, 0, 'Still should not be able to renew' );
651
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked' );
651
    is( $error->[0], 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked' );
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_too_soon limit is overridden' );
654
    is( $error->[0], 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
655
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
655
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
656
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
656
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
657
    is( $renewokay, 0, 'Still should not be able to renew' );
657
    is( $renewokay, 0, 'Still should not be able to renew' );
658
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
658
    is( $error->[0], 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
659
    ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber);
659
    ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber);
660
660
661
661
Lines 680-686 subtest "CanBookBeRenewed tests" => sub { Link Here
680
680
681
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
681
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
682
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
682
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
683
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
683
    is( $error->[0], 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
684
684
685
    # Bug 14395
685
    # Bug 14395
686
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
686
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
Lines 705-718 subtest "CanBookBeRenewed tests" => sub { Link Here
705
    ( $renewokay, $error ) =
705
    ( $renewokay, $error ) =
706
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
706
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
707
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
707
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
708
    is( $error, 'auto_too_soon',
708
    is( $error->[0], 'auto_too_soon',
709
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
709
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
710
    );
710
    );
711
711
712
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
712
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
713
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
713
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
714
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
714
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
715
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
715
    is( $error->[0], 'too_soon', 'Error is too_soon, no auto' );
716
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
716
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
717
717
718
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
718
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
Lines 721-734 subtest "CanBookBeRenewed tests" => sub { Link Here
721
    ( $renewokay, $error ) =
721
    ( $renewokay, $error ) =
722
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
722
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
723
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
723
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
724
    is( $error, 'auto_too_soon',
724
    is( $error->[0], 'auto_too_soon',
725
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
725
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
726
    );
726
    );
727
727
728
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
728
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
729
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
729
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
730
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
730
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
731
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
731
    is( $error->[0], 'too_soon', 'Error is too_soon, no auto' );
732
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
732
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
733
733
734
    # Change policy so that loans can be renewed 99 days prior to the due date
734
    # Change policy so that loans can be renewed 99 days prior to the due date
Lines 737-743 subtest "CanBookBeRenewed tests" => sub { Link Here
737
    ( $renewokay, $error ) =
737
    ( $renewokay, $error ) =
738
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
738
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
739
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
739
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
740
    is( $error, 'auto_renew',
740
    is( $error->[0], 'auto_renew',
741
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
741
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
742
    );
742
    );
743
743
Lines 776-782 subtest "CanBookBeRenewed tests" => sub { Link Here
776
        ( $renewokay, $error ) =
776
        ( $renewokay, $error ) =
777
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
777
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
778
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
778
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
779
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
779
        is( $error->[0], 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
780
780
781
        Koha::CirculationRules->set_rules(
781
        Koha::CirculationRules->set_rules(
782
            {
782
            {
Lines 792-798 subtest "CanBookBeRenewed tests" => sub { Link Here
792
        ( $renewokay, $error ) =
792
        ( $renewokay, $error ) =
793
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
793
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
794
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
794
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
795
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
795
        is( $error->[0], 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
796
796
797
        Koha::CirculationRules->set_rules(
797
        Koha::CirculationRules->set_rules(
798
            {
798
            {
Lines 808-814 subtest "CanBookBeRenewed tests" => sub { Link Here
808
        ( $renewokay, $error ) =
808
        ( $renewokay, $error ) =
809
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
809
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
810
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
810
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
811
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
811
        is( $error->[0], 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
812
812
813
        Koha::CirculationRules->set_rules(
813
        Koha::CirculationRules->set_rules(
814
            {
814
            {
Lines 824-830 subtest "CanBookBeRenewed tests" => sub { Link Here
824
        ( $renewokay, $error ) =
824
        ( $renewokay, $error ) =
825
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
825
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
826
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
826
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
827
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
827
        is( $error->[0],     'auto_renew', 'Cannot renew, renew is automatic' );
828
828
829
        Koha::CirculationRules->set_rules(
829
        Koha::CirculationRules->set_rules(
830
            {
830
            {
Lines 841-847 subtest "CanBookBeRenewed tests" => sub { Link Here
841
        ( $renewokay, $error ) =
841
        ( $renewokay, $error ) =
842
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
842
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
843
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
843
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
844
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
844
        is( $error->[0], 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
845
845
846
        Koha::CirculationRules->set_rules(
846
        Koha::CirculationRules->set_rules(
847
            {
847
            {
Lines 858-864 subtest "CanBookBeRenewed tests" => sub { Link Here
858
        ( $renewokay, $error ) =
858
        ( $renewokay, $error ) =
859
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
859
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
860
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
860
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
861
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
861
        is( $error->[0], 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
862
862
863
        Koha::CirculationRules->set_rules(
863
        Koha::CirculationRules->set_rules(
864
            {
864
            {
Lines 875-881 subtest "CanBookBeRenewed tests" => sub { Link Here
875
        ( $renewokay, $error ) =
875
        ( $renewokay, $error ) =
876
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
876
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
877
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
877
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
878
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
878
        is( $error->[0], 'auto_renew', 'Cannot renew, renew is automatic' );
879
    };
879
    };
880
880
881
    subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew & OPACFineNoRenewalsIncludeCredit" => sub {
881
    subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew & OPACFineNoRenewalsIncludeCredit" => sub {
Lines 921-927 subtest "CanBookBeRenewed tests" => sub { Link Here
921
        ( $renewokay, $error ) =
921
        ( $renewokay, $error ) =
922
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
922
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
923
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
923
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
924
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
924
        is( $error->[0], 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
925
925
926
        $account->add_debit(
926
        $account->add_debit(
927
            {
927
            {
Lines 935-941 subtest "CanBookBeRenewed tests" => sub { Link Here
935
        ( $renewokay, $error ) =
935
        ( $renewokay, $error ) =
936
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
936
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
937
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
937
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
938
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
938
        is( $error->[0], 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
939
939
940
        $account->add_debit(
940
        $account->add_debit(
941
            {
941
            {
Lines 949-955 subtest "CanBookBeRenewed tests" => sub { Link Here
949
        ( $renewokay, $error ) =
949
        ( $renewokay, $error ) =
950
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
950
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
951
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
951
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
952
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
952
        is( $error->[0], 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
953
953
954
        $account->add_credit(
954
        $account->add_credit(
955
            {
955
            {
Lines 962-974 subtest "CanBookBeRenewed tests" => sub { Link Here
962
        ( $renewokay, $error ) =
962
        ( $renewokay, $error ) =
963
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
963
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
964
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
964
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
965
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
965
        is( $error->[0], 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
966
966
967
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
967
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
968
        ( $renewokay, $error ) =
968
        ( $renewokay, $error ) =
969
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
969
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
970
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
970
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
971
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
971
        is( $error->[0], 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
972
972
973
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
973
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
974
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1');
974
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1');
Lines 1008-1014 subtest "CanBookBeRenewed tests" => sub { Link Here
1008
        ( $renewokay, $error ) =
1008
        ( $renewokay, $error ) =
1009
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1009
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1010
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1010
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1011
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1011
        is( $error->[0], 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1012
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1012
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1013
1013
1014
1014
Lines 1020-1026 subtest "CanBookBeRenewed tests" => sub { Link Here
1020
        ( $renewokay, $error ) =
1020
        ( $renewokay, $error ) =
1021
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1021
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1022
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1022
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1023
        is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
1023
        is( $error->[0], 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
1024
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1024
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1025
1025
1026
1026
Lines 1032-1038 subtest "CanBookBeRenewed tests" => sub { Link Here
1032
        ( $renewokay, $error ) =
1032
        ( $renewokay, $error ) =
1033
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1033
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1034
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1034
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1035
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1035
        is( $error->[0], 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1036
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1036
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1037
    };
1037
    };
1038
1038
Lines 1158-1164 subtest "CanBookBeRenewed tests" => sub { Link Here
1158
1158
1159
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1159
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
1160
    is( $renewokay, 0, 'Cannot renew, 0 renewals allowed');
1160
    is( $renewokay, 0, 'Cannot renew, 0 renewals allowed');
1161
    is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1161
    is( $error->[0], 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
1162
1162
1163
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1163
    # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
1164
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
1164
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
Lines 1547-1553 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1547
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1547
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1548
    my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $item->itemnumber );
1548
    my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $item->itemnumber );
1549
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1549
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1550
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1550
    is( $error->[0], 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1551
}
1551
}
1552
1552
1553
{
1553
{
Lines 3415-3421 subtest 'ItemsDeniedRenewal preference' => sub { Link Here
3415
    ( $idr_mayrenew, $idr_error ) =
3415
    ( $idr_mayrenew, $idr_error ) =
3416
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3416
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3417
    is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' );
3417
    is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' );
3418
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' );
3418
    is( $idr_error->[0], 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' );
3419
    ( $idr_mayrenew, $idr_error ) =
3419
    ( $idr_mayrenew, $idr_error ) =
3420
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3420
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3421
    is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' );
3421
    is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' );
Lines 3427-3433 subtest 'ItemsDeniedRenewal preference' => sub { Link Here
3427
    ( $idr_mayrenew, $idr_error ) =
3427
    ( $idr_mayrenew, $idr_error ) =
3428
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3428
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3429
    is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' );
3429
    is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' );
3430
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' );
3430
    is( $idr_error->[0], 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' );
3431
    ( $idr_mayrenew, $idr_error ) =
3431
    ( $idr_mayrenew, $idr_error ) =
3432
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3432
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3433
    is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
3433
    is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
Lines 3439-3445 subtest 'ItemsDeniedRenewal preference' => sub { Link Here
3439
    ( $idr_mayrenew, $idr_error ) =
3439
    ( $idr_mayrenew, $idr_error ) =
3440
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3440
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
3441
    is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
3441
    is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
3442
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' );
3442
    is( $idr_error->[0], 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' );
3443
    ( $idr_mayrenew, $idr_error ) =
3443
    ( $idr_mayrenew, $idr_error ) =
3444
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3444
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
3445
    is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
3445
    is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
3446
- 

Return to bug 25758