From 6c75695542e2416a52dab1776c751601188aad93 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 13 May 2021 12:04:41 -0400 Subject: [PATCH] Bug 14364: (QA follow-up) Generate message for transfers as well Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/Reserves.pm | 49 ++++++++++++++++++- t/db_dependent/Holds/ExpireReservesAutoFill.t | 16 +++--- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 5cdb2b6a0a..90d4e56cbe 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1243,12 +1243,14 @@ sub ModReserveAffect { $hold->set_processing(); } else { $hold->set_waiting($desk_id); - _koha_notify_reserve( $hold->reserve_id, $notify_library ) unless $already_on_shelf; + _koha_notify_reserve( $hold->reserve_id ) unless $already_on_shelf; # Complete transfer if one exists my $transfer = $hold->item->get_transfer; $transfer->receive if $transfer; } + _koha_notify_hold_changed( $hold ) if $notify_library; + _FixPriority( { biblionumber => $biblionumber } ); my $item = Koha::Items->find($itemnumber); if ( $item->location && $item->location eq 'CART' @@ -1975,6 +1977,51 @@ sub _koha_notify_reserve { } } +=head2 _koha_notify_hold_changed + + _koha_notify_hold_changed( $hold_object ); + +=cut + +sub _koha_notify_hold_changed { + my $hold = shift; + + my $patron = $hold->patron; + my $library = $hold->branch; + + my $letter = C4::Letters::GetPreparedLetter( + module => 'reserves', + letter_code => 'HOLD_CHANGED', + branchcode => $hold->branchcode, + substitute => { today => output_pref( dt_from_string ) }, + tables => { + 'branches' => $library->unblessed, + 'borrowers' => $patron->unblessed, + 'biblio' => $hold->biblionumber, + 'biblioitems' => $hold->biblionumber, + 'reserves' => $hold->unblessed, + 'items' => $hold->itemnumber, + }, + ); + + return unless $letter; + + my $email = + C4::Context->preference('ExpireReservesAutoFillEmail') + || $library->branchemail + || C4::Context->preference('KohaAdminEmailAddress'); + + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->id, + message_transport_type => 'email', + from_address => $email, + to_address => $email, + } + ); +} + =head2 _ShiftPriority $new_priority = _ShiftPriority( $biblionumber, $priority ); diff --git a/t/db_dependent/Holds/ExpireReservesAutoFill.t b/t/db_dependent/Holds/ExpireReservesAutoFill.t index 610e3ba747..d805c50029 100755 --- a/t/db_dependent/Holds/ExpireReservesAutoFill.t +++ b/t/db_dependent/Holds/ExpireReservesAutoFill.t @@ -100,11 +100,11 @@ subtest 'Test automatically canceled expired waiting holds to fill the next hold CancelExpiredReserves(); - my @holds = Koha::Holds->search( {}, { order_by => 'priority' } ); - $hold_2 = $holds[0]; - $hold_3 = $holds[1]; + my $holds = Koha::Holds->search( {}, { order_by => 'priority' } ); + $hold_2 = $holds->next; + $hold_3 = $holds->next; - is( @holds, 2, 'Found 2 holds' ); + is( $holds->count, 2, 'Found 2 holds' ); is( $hold_2->priority, 0, 'Next hold in line now has priority of 0' ); is( $hold_2->found, 'W', 'Next hold in line is now set to waiting' ); @@ -117,10 +117,10 @@ subtest 'Test automatically canceled expired waiting holds to fill the next hold CancelExpiredReserves(); - @holds = Koha::Holds->search( {}, { order_by => 'priority' } ); - $hold_3 = $holds[0]; + $holds = Koha::Holds->search( {}, { order_by => 'priority' } ); + $hold_3 = $holds->next; - is( @holds, 1, 'Found 1 hold' ); + is( $holds->count, 1, 'Found 1 hold' ); is( $hold_3->priority, 0, 'Next hold in line now has priority of 0' ); is( $hold_3->found, 'W', 'Next hold in line is now set to waiting' ); @@ -186,5 +186,5 @@ subtest 'Test automatically canceled expired waiting holds to fill the next hold my @messages = $schema->resultset('MessageQueue') ->search( { letter_code => 'HOLD_CHANGED' } ); - is( @messages, 0, 'No messages in the message queue when generating transfer' ); + is( @messages, 1, 'Nessage is generated in the message queue when generating transfer' ); }; -- 2.39.5