From 68edf0d404bf4e25fd97097b09ec42ffc61d6b5b 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 --- C4/Circulation.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 95630a6f8a1..6f11e3f541a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3413,6 +3413,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 @@ -3422,13 +3424,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->unblessed, $patron->unblessed ); @@ -3437,7 +3441,7 @@ sub GetSoonestRenewDate { itemtype => $item->effective_itemtype, branchcode => $branchcode, rules => [ - 'norenewalbefore', + $circ_rule, 'lengthunit', ] } @@ -3445,12 +3449,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' ) @@ -3458,8 +3462,8 @@ sub GetSoonestRenewDate { $soonestrenewal->truncate( to => 'day' ); } return $soonestrenewal if $now < $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' ) @@ -4552,7 +4556,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.30.2