From e6c31093a4bdd774df880d8197e91bf0ec6ee7c5 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 3 Jul 2025 20:26:36 +0000 Subject: [PATCH] Bug 39820: Add cancellation reason and clean up cancellation request --- C4/SIP/ILS/Transaction/Checkin.pm | 5 ++++- t/db_dependent/SIP/Transaction.t | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index 516e141d576..94087723a84 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -94,7 +94,10 @@ sub do_checkin { if ($item) { my $waiting_holds_to_be_cancelled = $item->holds->waiting->filter_by_has_cancellation_requests; while ( my $hold = $waiting_holds_to_be_cancelled->next ) { - $hold->cancel; + my $cancellation_request = $hold->cancellation_requests; + $cancellation_request->delete; + my $cancel_params->{cancellation_reason} = "Cancelled by SIP"; + $hold->cancel($cancel_params); } } diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index 8482d3c3ce1..16487922cac 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -711,7 +711,7 @@ subtest do_checkin => sub { }; subtest 'cancel_waiting_holds_with_cancellation_requests at checkin' => sub { - plan tests => 5; + plan tests => 6; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $patron1 = $builder->build_object( @@ -758,6 +758,19 @@ subtest 'cancel_waiting_holds_with_cancellation_requests at checkin' => sub { 'Hold has a cancellation request' ); + #Create a HOLD_CANCELLATION notice + my $template = Koha::Notice::Template->new( + { + module => 'reserves', + code => 'HOLD_CANCELLATION', + branchcode => '', + message_transport_type => 'email', + title => 'Hold Cancellation', + content => 'Your hold has been cancelled.', + is_html => 0, + } + )->store; + my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); my $transaction = C4::SIP::ILS::Transaction::Checkin->new(); @@ -766,17 +779,15 @@ subtest 'cancel_waiting_holds_with_cancellation_requests at checkin' => sub { # Check if the hold still exists $hold_obj = Koha::Holds->find($hold); - ok( !defined( $hold_obj ), 'Hold has been cancelled and deleted' ); + ok( !defined($hold_obj), 'Hold has been cancelled and deleted' ); my $old_hold = Koha::Old::Holds->find($hold); - ok( $old_hold, 'Hold was moved to old reserves'); - # QUESTION: Should the cancellation reason be set to "Cancelled by SIP"? - is( $old_hold->cancellation_reason, undef, 'No cancellation reason was set' ); - - # FIXME: What should happen to the cancellation request? - # Check that the cancellation request is deleted - # my $existing_cancellation_requests = Koha::Hold::CancellationRequests->search( { hold_id => $hold } ); - # is( $existing_cancellation_requests->count, 0, 'Cancellation request is deleted after processing' ); + ok( $old_hold, 'Hold was moved to old reserves' ); + is( $old_hold->cancellation_reason, "Cancelled by SIP", 'Cancellation reason set to Cancelled by SIP' ); + + #Check that the cancellation request is deleted + my $existing_cancellation_requests = Koha::Hold::CancellationRequests->search( { hold_id => $hold } ); + is( $existing_cancellation_requests->count, 0, 'Cancellation request is deleted after processing' ); # Verify the item's hold count is( $item->holds->count, 0, 'No holds remain on the item after cancellation' ); -- 2.39.5