From 3ddf87aef66957b3930b9c3fafbea16d15c5b580 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 11 Aug 2023 13:37:08 +0000 Subject: [PATCH] Bug 25393: Distinguish between auto or normal renewals in GetSoonestRenewDate Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3b20e8ab93..b2bbabbc05 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3433,6 +3433,8 @@ C<$patron> is the patron who currently has the item on loan. C<$issue> is the the item issue. +C<$is_auto> is this soonest renew date for an auto renewal? + C<$GetSoonestRenewDate> returns the DateTime of the soonest possible renew date, based on the value "No renewal before" of the applicable issuing rule. Returns the current date if the item can already be @@ -3442,13 +3444,15 @@ cannot be found. =cut sub GetSoonestRenewDate { - my ( $patron, $issue ) = @_; + my ( $patron, $issue, $is_auto ) = @_; return unless $issue; return unless $patron; my $item = $issue->item; return unless $item; + my $circ_rule = $is_auto ? 'noautorenewalbefore' : 'norenewalbefore'; + my $dbh = C4::Context->dbh; my $branchcode = _GetCircControlBranch( $item, $patron ); @@ -3457,7 +3461,7 @@ sub GetSoonestRenewDate { itemtype => $item->effective_itemtype, branchcode => $branchcode, rules => [ - 'norenewalbefore', + $circ_rule, 'lengthunit', ] } @@ -3465,12 +3469,12 @@ sub GetSoonestRenewDate { my $now = dt_from_string; - if ( defined $issuing_rule->{norenewalbefore} - and $issuing_rule->{norenewalbefore} ne "" ) + if ( defined $issuing_rule->{$circ_rule} + and $issuing_rule->{$circ_rule} ne "" ) { my $soonestrenewal = dt_from_string( $issue->date_due )->subtract( - $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); + $issuing_rule->{lengthunit} => $issuing_rule->{$circ_rule} ); if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' and $issuing_rule->{lengthunit} eq 'days' ) @@ -3478,8 +3482,8 @@ sub GetSoonestRenewDate { $soonestrenewal->truncate( to => 'day' ); } return $soonestrenewal; - } elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) { - # Checkouts with auto-renewing fall back to due date + } elsif ( $is_auto && $issue->auto_renew && $patron->autorenew_checkouts ) { + # Checkouts with auto-renewing fall back to due date if noautorenewalbefore is undef my $soonestrenewal = dt_from_string( $issue->date_due ); if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' and $issuing_rule->{lengthunit} eq 'days' ) @@ -4572,7 +4576,7 @@ sub _CanBookBeAutoRenewed { } } - my $soonest = GetSoonestRenewDate($patron, $issue); + my $soonest = GetSoonestRenewDate( $patron, $issue, 1 ); if ( $soonest > dt_from_string() ) { return ( "auto_too_soon", $soonest ); -- 2.39.2