From 1bc9498f67374d6e89b3f538eb2c4c2e425b4649 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 6 Nov 2023 14:31:03 +0200 Subject: [PATCH] Bug 34032: Use reserves.patron_expiration_date if set If reserves.patron_expiration_date is set use it as holds expiration date when waiting status is reverted. To test: 1. Apply this patch. 2. Add hold for patron A and set expiration date manually. 3. Check in item on hold for patron A and confirm hold was set as waiting. 4. Revert holds waiting status. => Hold should still have expiration date you set manually in step 2. 5. Check that you have DefaultHoldExpirationdate and other DefaultHold sysprefs set. 6. Add hold for patron B, but this time do not set expiration date. 7. Check in item on hold for patron B, revert waiting status. => Hold should now have expiration date set based on DefaultHold sysprefs. Also prove t/db_dependent/Hold.t. Sponsored-by: Koha-Suomi Oy Signed-off-by: Esther --- Koha/Hold.pm | 13 +++++++------ t/db_dependent/Hold.t | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 748babfe9d..8b3aafa342 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -940,13 +940,14 @@ sub store { if ( exists $updated_columns{reservedate} || $hold_reverted ) { if ( ( C4::Context->preference('DefaultHoldExpirationdate') - && ! exists $updated_columns{expirationdate} ) - || ( C4::Context->preference('DefaultHoldExpirationdate') - && exists $updated_columns{expirationdate} - && $hold_reverted ) - ) + && ( ! exists $updated_columns{expirationdate} || $hold_reverted ) ) + ) { - $self->_set_default_expirationdate; + if($self->patron_expiration_date){ + $self->expirationdate($self->patron_expiration_date); + } else { + $self->_set_default_expirationdate; + } } } } diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index ce8488c844..fa607a5c2e 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 => 6; + plan tests => 7; $schema->storage->txn_begin(); @@ -241,6 +241,31 @@ subtest "store() tests" => sub { is( $hold->expirationdate, $expected_date, 'Expiration date set after reverting holds waiting status.' ); + my $patron_expiration_date = dt_from_string('2023-11-06')->ymd; + $hold = Koha::Hold->new( + { + biblionumber => $biblio->biblionumber, + itemnumber => $item->id, + reservedate => '2023-10-15', + expirationdate => $patron_expiration_date, + waitingdate => '2023-10-15', + borrowernumber => $borrower->borrowernumber, + branchcode => $library->branchcode, + suspend => 0, + patron_expiration_date => $patron_expiration_date, + } + )->store; + $hold->discard_changes; + + $hold->set_waiting; + C4::Reserves::RevertWaitingStatus( + { itemnumber => $item->itemnumber } + ); + $hold->discard_changes; + + is( $hold->expirationdate, + $patron_expiration_date, 'Expiration date set same as patron_expiration_date after reverting holds waiting status.' ); + $schema->storage->txn_rollback(); }; -- 2.30.2