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

(-)a/C4/Circulation.pm (-10 / +16 lines)
Lines 2637-2647 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2637
=cut
2637
=cut
2638
2638
2639
sub CanBookBeRenewed {
2639
sub CanBookBeRenewed {
2640
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2640
    my ( $borrowernumber, $itemnumber, $override_limit, $cron ) = @_;
2641
2641
2642
    my $dbh    = C4::Context->dbh;
2642
    my $dbh    = C4::Context->dbh;
2643
    my $renews = 1;
2643
    my $renews = 1;
2644
    my $auto_renew = 0;
2644
    my $auto_renew = "no";
2645
2645
2646
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2646
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2647
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2647
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
Lines 2739-2760 sub CanBookBeRenewed { Link Here
2739
2739
2740
            if ( $soonestrenewal > dt_from_string() )
2740
            if ( $soonestrenewal > dt_from_string() )
2741
            {
2741
            {
2742
                return ( 0, "auto_too_soon" ) if $issue->auto_renew && $patron->autorenew_checkouts;
2742
                $auto_renew = ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon";
2743
                return ( 0, "too_soon" );
2744
            }
2743
            }
2745
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2744
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2746
                $auto_renew = 1;
2745
                $auto_renew = "ok";
2747
            }
2746
            }
2748
        }
2747
        }
2749
2748
2750
        # Fallback for automatic renewals:
2749
        # Fallback for automatic renewals:
2751
        # If norenewalbefore is undef, don't renew before due date.
2750
        # If norenewalbefore is undef, don't renew before due date.
2752
        if ( $issue->auto_renew && !$auto_renew && $patron->autorenew_checkouts ) {
2751
        if ( $issue->auto_renew && $auto_renew eq "no" && $patron->autorenew_checkouts ) {
2753
            my $now = dt_from_string;
2752
            my $now = dt_from_string;
2754
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2753
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2755
                $auto_renew = 1;
2754
                $auto_renew = "ok";
2756
            } else {
2755
            } else {
2757
                return ( 0, "auto_too_soon" );
2756
                $auto_renew = "auto_too_soon";
2758
            }
2757
            }
2759
        }
2758
        }
2760
    }
2759
    }
Lines 2833-2840 sub CanBookBeRenewed { Link Here
2833
            }
2832
            }
2834
        }
2833
        }
2835
    }
2834
    }
2836
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2835
    if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve'
2837
    return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed
2836
        return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2837
        return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2838
    } else { # For other purposes we want 'on_reserve' before 'too_soon'
2839
        return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2840
        return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2841
    }
2842
2843
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2838
2844
2839
    return ( 1, undef );
2845
    return ( 1, undef );
2840
}
2846
}
(-)a/misc/cronjobs/automatic_renewals.pl (-1 / +1 lines)
Lines 88-94 print "Test run only\n" unless $confirm; Link Here
88
while ( my $auto_renew = $auto_renews->next ) {
88
while ( my $auto_renew = $auto_renews->next ) {
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, undef, 1 );
92
    if ( $error eq 'auto_renew' ) {
92
    if ( $error eq 'auto_renew' ) {
93
        if ($verbose) {
93
        if ($verbose) {
94
            say sprintf "Issue id: %s for borrower: %s and item: %s ". ( $confirm ? 'will' : 'would') . " be renewed.",
94
            say sprintf "Issue id: %s for borrower: %s and item: %s ". ( $confirm ? 'will' : 'would') . " be renewed.",
(-)a/t/db_dependent/Circulation.t (-3 / +8 lines)
Lines 278-284 Koha::CirculationRules->set_rules( Link Here
278
278
279
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
279
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
280
subtest "CanBookBeRenewed tests" => sub {
280
subtest "CanBookBeRenewed tests" => sub {
281
    plan tests => 83;
281
    plan tests => 87;
282
282
283
    C4::Context->set_preference('ItemsDeniedRenewal','');
283
    C4::Context->set_preference('ItemsDeniedRenewal','');
284
    # Generate test biblio
284
    # Generate test biblio
Lines 649-658 subtest "CanBookBeRenewed tests" => sub { Link Here
649
    );
649
    );
650
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
650
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
651
    is( $renewokay, 0, 'Still should not be able to renew' );
651
    is( $renewokay, 0, 'Still should not be able to renew' );
652
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked' );
652
    is( $error, 'on_reserve', 'returned code is on_reserve, reserve checked when not checking for cron' );
653
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, undef, 1 );
654
    is( $renewokay, 0, 'Still should not be able to renew' );
655
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' );
653
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
656
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
654
    is( $renewokay, 0, 'Still should not be able to renew' );
657
    is( $renewokay, 0, 'Still should not be able to renew' );
655
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
658
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
659
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1, 1 );
660
    is( $renewokay, 0, 'Still should not be able to renew' );
661
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
656
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
662
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
657
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
663
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
658
    is( $renewokay, 0, 'Still should not be able to renew' );
664
    is( $renewokay, 0, 'Still should not be able to renew' );
659
- 

Return to bug 25758