Bug 14395: Code changes
This patch updates the calculation of 'No renewal before' to include the new syspref NoRenewalBeforePrecision. To test: 1) Check out an hour-based loan with 'No renewal before' set to 1. Switch syspref NoRenewalBeforePrecision between 'date' and 'exact time'. Confirm that with both settings the item cannot be renewed until exactly one hour before due. 2) Check out a day-based loan with 'No renewal before' set to 1 day. Confirm that: * with NoRenewalBeforePrecision set to 'date', renewal is possible at 12:00 AM on the day before due. * with NoRenewalBeforePrecision set to 'exact time', renewal is possible at 11:59 PM on the day before due. Sponsored-by: Hochschule für Gesundheit (hsg), Germany Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
This commit is contained in:
parent
77abb023cb
commit
b52e879209
1 changed files with 22 additions and 11 deletions
|
@ -2832,14 +2832,20 @@ sub CanBookBeRenewed {
|
|||
and $issuingrule->{norenewalbefore} ne "" )
|
||||
{
|
||||
|
||||
# Get current time and add norenewalbefore.
|
||||
# If this is smaller than date_due, it's too soon for renewal.
|
||||
my $now = dt_from_string;
|
||||
if (
|
||||
$now->add(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
|
||||
) < $itemissue->{date_due}
|
||||
)
|
||||
# Calculate soonest renewal by subtracting 'No renewal before' from due date
|
||||
my $soonestrenewal =
|
||||
$itemissue->{date_due}->clone()
|
||||
->subtract(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
|
||||
|
||||
# Depending on syspref reset the exact time, only check the date
|
||||
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
|
||||
and $issuingrule->{lengthunit} eq 'days' )
|
||||
{
|
||||
$soonestrenewal->truncate( to => 'day' );
|
||||
}
|
||||
|
||||
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) )
|
||||
{
|
||||
return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew};
|
||||
return ( 0, "too_soon" );
|
||||
|
@ -3075,11 +3081,16 @@ sub GetSoonestRenewDate {
|
|||
and $issuingrule->{norenewalbefore} ne "" )
|
||||
{
|
||||
my $soonestrenewal =
|
||||
$itemissue->{date_due}->subtract(
|
||||
$itemissue->{date_due}->clone()
|
||||
->subtract(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
|
||||
|
||||
$soonestrenewal = $now > $soonestrenewal ? $now : $soonestrenewal;
|
||||
return $soonestrenewal;
|
||||
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
|
||||
and $issuingrule->{lengthunit} eq 'days' )
|
||||
{
|
||||
$soonestrenewal->truncate( to => 'day' );
|
||||
}
|
||||
return $soonestrenewal if $now < $soonestrenewal;
|
||||
}
|
||||
return $now;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue