Bug 12063 - Keep patron's requested expiration date if it is prior to the calculated one

Signed-off-by: Andreas Hedström Mace <andreas.hedstrom.mace@sub.su.se>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Alex Arnaud 2017-01-18 14:13:33 +00:00 committed by Kyle M Hall
parent d477cc24f6
commit 8fc7744258
2 changed files with 45 additions and 3 deletions

View File

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

View File

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