Bug 39820: Add cancellation reason and clean up cancellation request

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit f2adf0ad82)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Lucas Gass 2025-07-03 20:26:36 +00:00 committed by Paul Derscheid
parent bb8da54478
commit 54728d4f68
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 24 additions and 10 deletions

View File

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

View File

@ -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' );
ok( $old_hold, 'Hold was moved to old reserves' );
is( $old_hold->cancellation_reason, "Cancelled by SIP", 'Cancellation reason set to Cancelled by SIP' );
# 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' );
#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' );