From c5441d311ad9285a0d699b4512f61eb18359bd4d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 15 Jan 2020 01:21:05 +0000 Subject: [PATCH] Bug 19014: on_reserve blocks auto_renew --- C4/Circulation.pm | 14 +++++++++----- t/db_dependent/Circulation.t | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 8978ba016d..a9b96848e8 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2668,6 +2668,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' ); @@ -2761,17 +2762,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" ); + } } } @@ -2841,6 +2844,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 ); } diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index d818cb9ac5..8c7bd9b72e 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -277,7 +277,7 @@ $dbh->do( 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 @@ -617,6 +617,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 issuingrules SET norenewalbefore = 0'); + ( $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); -- 2.11.0