From 8de0a02bd236e7fba0edf02cefa0a51f3835805f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 29 Apr 2022 12:58:44 +0000 Subject: [PATCH] Bug 30167: (follow-up) Return a hash with soonest_renew_date Signed-off-by: Marcel de Rooy Signed-off-by: Fridolin Somers --- C4/Circulation.pm | 9 +++++---- circ/renew.pl | 2 +- opac/opac-user.pl | 2 +- svc/checkouts | 2 +- t/db_dependent/Circulation.t | 14 +++++++------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c8e98a71ca..e809e3d873 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2838,7 +2838,8 @@ item must currently be on loan to the specified borrower; renewals must be allowed for the item's type; and the borrower must not have already renewed the loan. $error will contain the reason the renewal can not proceed - $info will contain the soonest renewal date if the error is 'too soon' + $info will contain a hash of additional info + currently 'soonest_renew_date' if error is 'too soon' =cut @@ -2897,7 +2898,7 @@ sub CanBookBeRenewed { branchcode => $branchcode, issue => $issue }); - return ( 0, $auto_renew, $soonest ) if $auto_renew =~ 'auto_too_soon' && $cron; + return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'auto_too_soon' && $cron; # cron wants 'too_soon' over 'on_reserve' for performance and to avoid # extra notices being sent. Cron also implies no override return ( 0, $auto_renew ) if $auto_renew =~ 'auto_account_expired'; @@ -3000,10 +3001,10 @@ sub CanBookBeRenewed { } return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found - return ( 0, $auto_renew, $soonest ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; + return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; $soonest = GetSoonestRenewDate($borrowernumber, $itemnumber); if ( $soonest > dt_from_string() ){ - return (0, "too_soon", $soonest ) unless $override_limit; + return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit; } return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed diff --git a/circ/renew.pl b/circ/renew.pl index 36a848919e..5a1ca18ef8 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -83,7 +83,7 @@ if ($barcode) { } if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) { - $soonest_renew_date = $info; + $soonest_renew_date = $info->{soonest_renew_date}; } if ( $error && ( $error eq 'auto_too_late' ) ) { $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate( diff --git a/opac/opac-user.pl b/opac/opac-user.pl index ed3d4e0513..35fe373947 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -254,7 +254,7 @@ if ( $pending_checkouts->count ) { # Useless test if ( $renewerror eq 'too_soon' ) { $issue->{'too_soon'} = 1; - $issue->{'soonestrenewdate'} = $info; + $issue->{'soonestrenewdate'} = $info->{soonest_renew_date}; } } diff --git a/svc/checkouts b/svc/checkouts index 0dfcaf1f91..7c28c2703d 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -160,7 +160,7 @@ while ( my $c = $sth->fetchrow_hashref() ) { $can_renew_error && $can_renew_error eq 'too_soon' ? output_pref( { - dt => $info, + dt => $info->{soonest_renew_date}, as_due_date => 1 } ) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index fcfcf90d71..34b16f5644 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -800,7 +800,7 @@ subtest "CanBookBeRenewed tests" => sub { is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); is( $error, 'auto_too_soon', 'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' ); - is( $info, $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); + is( $info->{soonest_renew_date} , $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); AddReserve( { branchcode => $branch, @@ -822,7 +822,7 @@ subtest "CanBookBeRenewed tests" => sub { ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, undef, 1 ); is( $renewokay, 0, 'Still should not be able to renew' ); is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' ); - is( $info, $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); + is( $info->{soonest_renew_date}, $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); ( $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' ); @@ -858,7 +858,7 @@ subtest "CanBookBeRenewed tests" => sub { ( $renewokay, $error, $info ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature'); is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)'); - is( $info, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); + is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); # Bug 14101 # Test premature automatic renewal @@ -868,13 +868,13 @@ subtest "CanBookBeRenewed tests" => sub { is( $error, 'auto_too_soon', 'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)' ); - is( $info, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'"); + is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'"); $renewing_borrower_obj->autorenew_checkouts(0)->store; ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' ); is( $error, 'too_soon', 'Error is too_soon, no auto' ); - is( $info, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); + is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); $renewing_borrower_obj->autorenew_checkouts(1)->store; # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date) @@ -886,13 +886,13 @@ subtest "CanBookBeRenewed tests" => sub { is( $error, 'auto_too_soon', 'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)' ); - is( $info, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); + is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); $renewing_borrower_obj->autorenew_checkouts(0)->store; ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' ); is( $error, 'too_soon', 'Error is too_soon, no auto' ); - is( $info, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); + is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); $renewing_borrower_obj->autorenew_checkouts(1)->store; # Change policy so that loans can be renewed 99 days prior to the due date -- 2.39.5