From 3e81a074f2f13c1059a27cdbd2af28f61bf94849 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 5 Feb 2024 14:44:46 -0500 Subject: [PATCH] Bug 35997: Cancelling a hold should remove the hold from the queue Test plan: 1) Place a hold for a record for a patron 2) Build the holds queue 3) Note the holds queue contains a match for that patron and record 4) Cancel the holds queue 5) Reload the holds queue page, note the match for that patron and record is gone! --- Koha/Hold.pm | 15 ++++++++++ t/db_dependent/HoldsQueue.t | 55 ++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 0224d019b76..a74ed95b586 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -706,6 +706,21 @@ sub cancel { $self->cancellation_reason( $params->{cancellation_reason} ); $self->store(); + my $dbh = $self->_result->result_source->schema->storage->dbh; + $dbh->do( + q{ + DELETE q, t + FROM tmp_holdsqueue q + INNER JOIN hold_fill_targets t + ON q.borrowernumber = t.borrowernumber + AND q.biblionumber = t.biblionumber + AND q.itemnumber = t.itemnumber + AND q.item_level_request = t.item_level_request + AND q.holdingbranch = t.source_branchcode + WHERE t.reserve_id = ? + }, undef, $self->id + ); + if ( $params->{cancellation_reason} ) { my $letter = C4::Letters::GetPreparedLetter( module => 'reserves', diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 7875c69eedd..dbd1d23872b 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,7 +8,7 @@ use Modern::Perl; -use Test::More tests => 61; +use Test::More tests => 62; use Data::Dumper; use C4::Calendar qw( new insert_single_holiday ); @@ -2091,3 +2091,56 @@ subtest "GetItemsAvailableToFillHoldsRequestsForBib" => sub { is_deeply( [$items->[0]->{itemnumber},$items->[1]->{itemnumber}],[$item_2->itemnumber,$item_3->itemnumber],"Correct two items retrieved"); }; + +subtest "Canceled holds should be removed from the holds queue" => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 ); + t::lib::Mocks::mock_preference( 'UseTransportCostMatrix', 0 ); + + my $branch1 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); + my $patron = $builder->build_object( + { + class => "Koha::Patrons", + value => { + branchcode => $branch1->branchcode, + categorycode => $category->categorycode + } + } + ); + + my $biblio = $builder->build_sample_biblio(); + my $item1 = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $branch1->branchcode, + } + ); + + my $reserve_id = AddReserve( + { + branchcode => $branch1->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => 1, + } + ); + + C4::HoldsQueue::CreateQueue(); + my $rs = $schema->resultset('TmpHoldsqueue'); + + is( $rs->search( { biblionumber => $biblio->biblionumber } )->count, 1, "Found the hold in the holds queue" ); + + Koha::Holds->find($reserve_id)->cancel(); + + is( + $rs->search( { biblionumber => $biblio->biblionumber } )->count, 0, + "Hold is no longer found in the holds queue after cancellation" + ); + + $schema->storage->txn_rollback; +}; -- 2.30.2