Bug 25393: Distinguish between auto or normal renewals in GetSoonestRenewDate

Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Pedro Amorim 2023-08-11 13:37:08 +00:00 committed by Tomas Cohen Arazi
parent 9fabc2f0b8
commit 3ddf87aef6
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -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 );