From 15b341babcbd5f16049344162d172ca1cad9918e Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 7 Dec 2021 04:07:09 +0000 Subject: [PATCH] Bug 24194: (follow-up) Use ExpireReservesMaxPickUpDelay when setting hold waiting If ExpireReservesMaxPickUpDelay is disabled then we don't need to set an expiration date when setting a hold as waiting --- Koha/Hold.pm | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 8ef19de31a..a8b776226c 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -185,37 +185,38 @@ sub set_waiting { desk_id => $desk_id, }; - if ( !C4::Context->preference('ReserveExpiration') ){ - $values->{expirationdate} = undef; - } else { - my $requested_expiration; - if ($self->expirationdate) { - $requested_expiration = dt_from_string($self->expirationdate); - } + my $requested_expiration; + if ($self->expirationdate) { + $requested_expiration = dt_from_string($self->expirationdate); + } - my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); - my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); + my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); + my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); - my $expirationdate = $today->clone; - $expirationdate->add(days => $max_pickup_delay); + my $expirationdate = $today->clone; + $expirationdate->add(days => $max_pickup_delay); - if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) { - my $itemtype = $self->item ? $self->item->effective_itemtype : $self->biblio->itemtype; - my $daysmode = Koha::CirculationRules->get_effective_daysmode( - { - categorycode => $self->borrower->categorycode, - itemtype => $itemtype, - branchcode => $self->branchcode, - } - ); - my $calendar = Koha::Calendar->new( branchcode => $self->branchcode, days_mode => $daysmode ); - $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay ); - } + if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) { + my $itemtype = $self->item ? $self->item->effective_itemtype : $self->biblio->itemtype; + my $daysmode = Koha::CirculationRules->get_effective_daysmode( + { + categorycode => $self->borrower->categorycode, + itemtype => $itemtype, + branchcode => $self->branchcode, + } + ); + my $calendar = Koha::Calendar->new( branchcode => $self->branchcode, days_mode => $daysmode ); + $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay ); + } + if ( C4::Context->preference('ExpireReservesMaxPickUpDelay') ) { # If patron's requested expiration date is prior to the # calculated one, we keep the patron's one. my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0; $values->{expirationdate} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd; + } else { + # if holds don't need a waiting expiration date to be expired automatically, don't set one + $values->{expirationdate} = undef; } $self->set($values)->store(); -- 2.11.0