From 03efe5ba76c80b9ed64de58d292155053a80c012 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Wed, 21 Jun 2023 14:36:08 +0300 Subject: [PATCH] Bug 34032: Set new expirationdate if waiting status is reverted When one reverts holds waiting status holds expiration date is not set even if DefaultHoldExpirationdate syspref is enabled. This patch adds new param hold_reverted to be used when RevertWaitingStatus is used to determine if expiration date should be set again. To test: 1) Make sure you have DefaultHoldExpirationdate syspref enabled. 2) Find hold with status "Waiting". 3) Revert waiting status. => Note that hold has no expiration date set. 4) Apply this patch. 5) Repeat steps 2 and 3. => Expiration date should now be set based on reserve date. Also prove t/db_dependent/Hold.t. Sponsored-by: Koha-Suomi Oy Signed-off-by: Sam Lau Signed-off-by: Esther Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- C4/Reserves.pm | 2 +- Koha/Hold.pm | 14 +++++++++----- t/db_dependent/Hold.t | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index c95a3d7ad4..f972109e86 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2167,7 +2167,7 @@ sub RevertWaitingStatus { expirationdate => $hold->patron_expiration_date, itemnumber => $hold->item_level_hold ? $hold->itemnumber : undef, } - )->store(); + )->store({ hold_reverted => 1 }); logaction( 'HOLDS', 'MODIFY', $hold->id, $hold ) if C4::Context->preference('HoldsLog'); diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 6ea8fc5756..8917e85dab 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -941,7 +941,9 @@ expirationdate for holds. =cut sub store { - my ($self) = @_; + my ($self, $params) = @_; + + my $hold_reverted = $params->{hold_reverted} // 0; Koha::Exceptions::Hold::MissingPickupLocation->throw() unless $self->branchcode; @@ -962,11 +964,13 @@ sub store { my %updated_columns = $self->_result->get_dirty_columns; return $self->SUPER::store unless %updated_columns; - - if ( exists $updated_columns{reservedate} ) { + if ( exists $updated_columns{reservedate} || $hold_reverted ) { if ( - C4::Context->preference('DefaultHoldExpirationdate') - && ! exists $updated_columns{expirationdate} + ( C4::Context->preference('DefaultHoldExpirationdate') + && ! exists $updated_columns{expirationdate} ) + || ( C4::Context->preference('DefaultHoldExpirationdate') + && exists $updated_columns{expirationdate} + && $hold_reverted ) ) { $self->_set_default_expirationdate; diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index 73007c18a0..ce8488c844 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -146,7 +146,7 @@ $schema->storage->txn_rollback(); subtest "store() tests" => sub { - plan tests => 5; + plan tests => 6; $schema->storage->txn_begin(); @@ -222,6 +222,25 @@ subtest "store() tests" => sub { is( $hold->expirationdate, $passed_date->ymd, 'Passed expiration date when updating hold correctly set (Passing both reservedate and expirationdate.' ); + $passed_date = dt_from_string('2023-06-20'); + $hold->set( + { + reservedate => $passed_date->ymd, + waitingdate => $passed_date->ymd, + } + )->store(); + $hold->discard_changes; + + $hold->set_waiting; + C4::Reserves::RevertWaitingStatus( + { itemnumber => $item->itemnumber } + ); + $hold->discard_changes; + + $expected_date = dt_from_string( $hold->reservedate )->add( years => 2 )->ymd; + is( $hold->expirationdate, + $expected_date, 'Expiration date set after reverting holds waiting status.' ); + $schema->storage->txn_rollback(); }; -- 2.20.1