From c31d9761740a51a7485b7592ae2c7110b32aed1f Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 20 Jul 2023 02:39:27 +0000 Subject: [PATCH] Bug 30362: Fix GetSoonestRenewDate to really return soonest renew date This change fixes GetSoonestRenewDate so that it returns the soonest renew date as calculated using "No Renewal Before" and "NoRenewalBeforePrecision". In the past, it would only return the soonest renew date if "$now" was lesser than it, which would typically only happen when using an "exact" precision rather than a "date" precision. Test plan: 0. Apply the patch 1. prove t/db_dependent/Circulation.t Signed-off-by: Sam Lau Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit f8c474019d74c9fd608206daf3074a79c5737f12) Signed-off-by: Fridolin Somers (cherry picked from commit 8fc3531e079d076a3212b2aa76525b5ca6e874bd) Signed-off-by: Matt Blenkinsop --- C4/Circulation.pm | 4 ++-- t/db_dependent/Circulation.t | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 891731d0ae..2e2f716272 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3405,8 +3405,8 @@ sub GetSoonestRenewDate { { $soonestrenewal->truncate( to => 'day' ); } - return $soonestrenewal if $now < $soonestrenewal; - } elsif ( $checkout->auto_renew && $patron->autorenew_checkouts ) { + return $soonestrenewal; + } elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) { # Checkouts with auto-renewing fall back to due date my $soonestrenewal = dt_from_string( $checkout->date_due ); if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 15aafac7ca..33b14c85f2 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -5775,12 +5775,13 @@ subtest "GetSoonestRenewDate tests" => sub { rule_value => 1, } ); - $issue->date_due( dt_from_string )->store; + $issue->date_due(dt_from_string)->store; is( GetSoonestRenewDate( $patron, $issue ), dt_from_string->subtract( days => 1 )->truncate( to => 'day' ), 'Checkouts with auto-renewal can be renewed 1 day before due date if no renewalbefore = 1 and precision = "date"' ); + }; subtest "CanBookBeIssued + needsconfirmation message" => sub { -- 2.39.5