From 1bc2703bb6724c03c760d1e442c80d55d689bfab Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Wed, 18 Jan 2017 14:13:33 +0000 Subject: [PATCH] Bug 12063 - Keep patron's requested expiration date if it is prior to the calculated one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreas Hedström Mace --- Koha/Hold.pm | 10 ++++++++- t/db_dependent/Holds/WaitingReserves.t | 38 ++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index c125bfc..1e2e730 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -127,6 +127,11 @@ sub set_waiting { waitingdate => $today->ymd, }; + my $requested_expiration; + if ($self->expirationdate) { + $requested_expiration = dt_from_string($self->expirationdate); + } + if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) { my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); @@ -139,7 +144,10 @@ sub set_waiting { $expirationdate = $calendar->days_forward( dt_from_string($self->waitingdate), $max_pickup_delay ); } - $values->{expirationdate} = $expirationdate->ymd; + # 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; } $self->set($values)->store(); diff --git a/t/db_dependent/Holds/WaitingReserves.t b/t/db_dependent/Holds/WaitingReserves.t index 6167f43..ccd677c 100644 --- a/t/db_dependent/Holds/WaitingReserves.t +++ b/t/db_dependent/Holds/WaitingReserves.t @@ -8,7 +8,7 @@ use Koha::DateUtils; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 10; +use Test::More tests => 11; use_ok('C4::Reserves'); @@ -77,6 +77,12 @@ my $biblio3 = $builder->build({ title => 'Title 3', }, }); +my $biblio4 = $builder->build({ + source => 'Biblio', + value => { + title => 'Title 4', }, +}); + my $item1 = $builder->build({ source => 'Item', value => { @@ -98,6 +104,13 @@ my $item3 = $builder->build({ }, }); +my $item4 = $builder->build({ + source => 'Item', + value => { + biblionumber => $biblio4->{biblionumber}, + }, +}); + my $today = dt_from_string(); my $reserve1_reservedate = $today->clone; @@ -167,7 +180,6 @@ my $reserve3 = $builder->build({ my $special_holiday1_dt = $today->clone; $special_holiday1_dt->add(days => 2); -Koha::Cache->get_instance()->flush_all(); my $holiday = $builder->build({ source => 'SpecialHoliday', value => { @@ -205,4 +217,26 @@ $expected_expiration->add(days => 8); my $r3 = Koha::Holds->find($reserve3->{reserve_id}); is($r3->expirationdate, $expected_expiration->ymd, 'Expiration date should be set to today + 7' ); +my $reserve4_reservedate = $today->clone; +my $requested_expiredate = $today->clone()->add(days => 6); + +my $reserve4 = $builder->build({ + source => 'Reserve', + value => { + borrowernumber => $patron2->{borrowernumber}, + reservedate => $reserve4_reservedate->ymd, + expirationdate => $requested_expiredate->ymd, + biblionumber => $biblio4->{biblionumber}, + branchcode => 'LIB1', + priority => 1, + found => '', + }, +}); + +t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 10); +ModReserveAffect( $item4->{itemnumber}, $patron2->{borrowernumber}, 0, $reserve4->{reserve_id}); + +my $r4 = Koha::Holds->find($reserve4->{reserve_id}); +is($r4->expirationdate, $requested_expiredate->ymd, 'Requested expiration date should be kept' ); + $dbh->rollback; \ No newline at end of file -- 2.1.4