@@ -, +, @@ --- C4/Circulation.pm | 14 +++++++++----- t/db_dependent/Circulation.t | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2693,6 +2693,7 @@ sub CanBookBeRenewed { my $dbh = C4::Context->dbh; my $renews = 1; + my $auto_renew = 0; my $item = Koha::Items->find($itemnumber) or return ( 0, 'no_item' ); my $issue = $item->checkout or return ( 0, 'no_checkout' ); @@ -2794,17 +2795,19 @@ sub CanBookBeRenewed { return ( 0, "too_soon" ); } elsif ( $issue->auto_renew ) { - return ( 0, "auto_renew" ); + $auto_renew = 1; } } # Fallback for automatic renewals: # If norenewalbefore is undef, don't renew before due date. - if ( $issue->auto_renew ) { + if ( $issue->auto_renew && !$auto_renew ) { my $now = dt_from_string; - return ( 0, "auto_renew" ) - if $now >= dt_from_string( $issue->date_due, 'sql' ); - return ( 0, "auto_too_soon" ); + if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){ + $auto_renew = 1; + } else { + return ( 0, "auto_too_soon" ); + } } } @@ -2874,6 +2877,7 @@ sub CanBookBeRenewed { } } return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found + return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed return ( 1, undef ); } --- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -274,7 +274,7 @@ Koha::CirculationRules->set_rules( my ( $reused_itemnumber_1, $reused_itemnumber_2 ); subtest "CanBookBeRenewed tests" => sub { - plan tests => 75; + plan tests => 77; C4::Context->set_preference('ItemsDeniedRenewal',''); # Generate test biblio @@ -622,6 +622,11 @@ subtest "CanBookBeRenewed tests" => sub { ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 ); is( $renewokay, 0, 'Still should not be able to renew' ); is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' ); + $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"'); + ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 ); + is( $renewokay, 0, 'Still should not be able to renew' ); + is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' ); + ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber); --