From 5fb97da59ee609f997edad2ba2f183418bc69b4a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 11 Jul 2022 17:35:27 -0300 Subject: [PATCH] Bug 22456: (QA follow-up) Consider cancellation requested as cancelled in OPAC This patch adds a helper method for filtering out cancellation requested-holds from resultsets, and makes use of it in the OPAC to filter out those in the current holds tab. Holds history now shows 'Waiting (cancellation requested)' on those. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- Koha/Holds.pm | 15 +++++++++++++++ .../bootstrap/en/includes/holds-table.inc | 4 +--- .../bootstrap/en/modules/opac-holdshistory.tt | 6 +++++- opac/opac-user.pl | 2 +- t/db_dependent/Koha/Holds.t | 13 +++++++++++-- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Koha/Holds.pm b/Koha/Holds.pm index 7bedab1a039..4ff90e679ed 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -163,6 +163,21 @@ sub filter_by_has_cancellation_requests { { join => 'cancellation_requests' } ); } +=head3 filter_out_has_cancellation_requests + + my $holds_without_cancellation_requests = $holds->filter_out_has_cancellation_requests; + +Returns a filtered resultset without holds with cancellation requests. + +=cut + +sub filter_out_has_cancellation_requests { + my ($self) = @_; + + return $self->search( { 'hold_cancellation_request_id' => { '=' => undef } }, + { join => 'cancellation_requests' } ); +} + =head2 Internal methods =head3 _type diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc index c6593006423..70b69010340 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc @@ -156,14 +156,12 @@ - [% ELSIF HOLD.cancellation_requests.count > 0 %] - [% ELSIF HOLD.is_waiting && HOLD.cancellation_requestable_from_opac %]
- +
[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-holdshistory.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-holdshistory.tt index d42eb7f18f2..81711426283 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-holdshistory.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-holdshistory.tt @@ -153,7 +153,11 @@ [% ELSIF hold.cancellationdate %] Cancelled [% ELSIF hold.found == 'W' %] - Waiting + [% IF hold.cancellation_requests.count == 0 %] + Waiting + [% ELSE %] + Cancelled + [% END %] [% ELSIF hold.found == 'T' %] In transit [% ELSE %] diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 147e7d9109b..ba45ddd2379 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -326,7 +326,7 @@ if ($show_barcode) { $template->param( show_barcode => 1 ) if $show_barcode; # now the reserved items.... -my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } ); +my $reserves = $patron->holds->filter_out_has_cancellation_requests; $template->param( RESERVES => $reserves, diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index 188ffd51c64..aec261dd1f7 100755 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -644,9 +644,9 @@ subtest 'set_waiting+patron_expiration_date' => sub { $schema->storage->txn_rollback; -subtest 'filter_by_has_cancellation_requests() tests' => sub { +subtest 'filter_by_has_cancellation_requests() and filter_out_has_cancellation_requests() tests' => sub { - plan tests => 4; + plan tests => 7; $schema->storage->txn_begin; @@ -699,6 +699,10 @@ subtest 'filter_by_has_cancellation_requests() tests' => sub { is( $filtered_rs->count, 0 ); + my $filtered_out_rs = $rs->filter_out_has_cancellation_requests; + + is( $filtered_out_rs->count, 3 ); + $hold_2->add_cancellation_request; $filtered_rs = $rs->filter_by_has_cancellation_requests; @@ -706,5 +710,10 @@ subtest 'filter_by_has_cancellation_requests() tests' => sub { is( $filtered_rs->count, 1 ); is( $filtered_rs->next->id, $hold_2->id ); + $filtered_out_rs = $rs->filter_out_has_cancellation_requests; + + is( $filtered_out_rs->count, 2 ); + is( $filtered_out_rs->next->id, $hold_1->id ); + $schema->storage->txn_rollback; }; -- 2.30.2