From bcefd90bc3d2902d390f455cd3221a930962df51 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 18 May 2022 17:38:37 -0300 Subject: [PATCH] Bug 22456: Staff interface handling This patch introduces a new tab to the 'Holds awaiting pickup' screen for holds that have cancellation requests. This can be accepted (by cancelling the hold) or rejected. To test: 1. Set circulation rules for cancellation requests, allowing them for certain item type. 2. Have some waiting holds for a patron on an item type that allows requesting cancellation. 3. Visit 'Holds awaiting pickup' => SUCCESS: No holds have cancellation requests 4. In the OPAC, on the user details, notice some holds have the ability to be requested cancellation. 5. Choose to request cancellation => SUCCESS: Request is placed, the button is disabled 6. In 'Holds awaiting pickup' you can see them 7. Play with rejecting/accepting => SUCCESS: It works! 8. Things are reflected in the OPAC side --- admin/columns_settings.yml | 31 +++++++++++++++++++ circ/waitingreserves.pl | 29 +++++++++++++++++ .../prog/en/includes/waiting_holds.inc | 17 ++++++++++ .../prog/en/modules/circ/waitingreserves.tt | 31 +++++++++++++++++-- 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index 6760a30c42..8d3dbdb8d1 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -1401,6 +1401,37 @@ modules: - columnname: action + holdscr: + columns: + - + columnname: checkbox + cannot_be_toggled: 1 + cannot_be_modified: 1 + - + columnname: waiting_since + - + columnname: date_hold_placed + - + columnname: expiration_date + - + columnname: title + - + columnname: patron + - + columnname: home_library + - + columnname: current_location + - + columnname: shelving_location + - + columnname: call_number + - + columnname: copy_number + - + columnname: enumeration + - + columnname: action + overdues: circ-overdues: default_display_length: 20 diff --git a/circ/waitingreserves.pl b/circ/waitingreserves.pl index 608fb49d3f..ec3c945c17 100755 --- a/circ/waitingreserves.pl +++ b/circ/waitingreserves.pl @@ -19,6 +19,8 @@ # along with Koha; if not, see . use Modern::Perl; + +use Try::Tiny; use CGI qw ( -utf8 ); use C4::Context; use C4::Output qw( output_html_with_http_headers ); @@ -28,6 +30,7 @@ use Date::Calc qw( Date_to_Days Today ); use C4::Reserves qw( ModReserve ModReserveCancelAll ); use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::BiblioFrameworks; +use Koha::Hold::CancellationRequests; use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; @@ -44,6 +47,8 @@ my $cancelall = $input->param('cancelall'); my $tab = $input->param('tab'); my $cancelBulk = $input->param('cancelBulk'); +my $reject_hold_cancellation_id = $input->param('reject_hold_cancellation_id'); + my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( { template_name => "circ/waitingreserves.tt", @@ -73,6 +78,26 @@ if ( C4::Context->preference('IndependentBranches') ) { } $template->param( all_branches => 1 ) if $all_branches; +# handle cancellation requests rejection +if ($reject_hold_cancellation_id) { + try { + Koha::Holds + ->find( $reject_hold_cancellation_id ) + ->cancellation_requests + ->filter_by_current + ->reject( $loggedinuser ); + } + catch { + if ( $_->isa('Koha::Exceptions::InvalidStatus') ) { + $template->param( reject_result_error => { invalid_status => $_->invalid_status } ); + } + else { + $template->param( reject_result_error => { unkown_error => "$_" } ); + warn "Unhandled exception when trying to reject a hold cancellation request: $_"; + } + }; +} + if ($cancelBulk) { my $reason = $input->param("cancellation-reason"); my @hold_ids = split( ',', scalar $input->param("ids") ); @@ -116,6 +141,8 @@ while ( my $hold = $holds->next ) { } +my $holds_with_cancellation_requests = Koha::Holds->waiting->filter_by_has_pending_cancellation_requests; + $template->param(cancel_result => \@cancel_result) if @cancel_result; $template->param( @@ -123,6 +150,8 @@ $template->param( reservecount => scalar @reserve_loop, overloop => \@over_loop, overcount => scalar @over_loop, + cancel_reqs_count => $holds_with_cancellation_requests->count, + cancel_reqs => $holds_with_cancellation_requests, show_date => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), tab => $tab, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc index 4738e44b5e..1d5b146e86 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc @@ -1,3 +1,4 @@ +[% USE KohaDates %] [% USE ItemTypes %] [% USE AuthorisedValues %] @@ -8,6 +9,9 @@ [% END %] + [% IF table_name == 'holdscr' %] + + [% END %] @@ -28,6 +32,13 @@ [% END %] + [% IF table_name == 'holdscr' %] + + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt index b6e06f7bc9..b70d1f8dc5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt @@ -48,6 +48,15 @@ View all libraries [% END %] + [% IF reject_result_error %] +
+ [% IF reject_result_error.invalid_status %] +

There was a problem rejecting the cancellation request. Cannot reject an already completed cancellation request.

+ [% ELSE %] +

Some error occurred while rejecting the cancellation request. Please check the logs

+ [% END %] +
+ [% END %] [% IF ( cancel_result ) %] [% FOREACH cancel_result %] [% IF ( messagetransfert ) %] @@ -88,6 +97,11 @@ Holds waiting over [% Koha.Preference('ReservesMaxPickUpDelay') | html %] days: [% overcount | html %] +
  • + + Holds with cancellation requests: [% cancel_reqs_count | html %] + +
  • @@ -125,6 +139,13 @@
    No holds found.
    [% END %]
    +
    + [% IF cancel_reqs_count %] + [% INCLUDE waiting_holds.inc select_column='1' table_name='holdscr' reserveloop=cancel_reqs tab='holdscr' %] + [% ELSE %] +
    No holds found.
    + [% END %] +
    [% END %] @@ -180,8 +201,9 @@ [% INCLUDE 'columns_settings.inc' %]
    Waiting since Date hold placedDate cancellation requestedExpiration date Title Patron[% reserveloo.waitingdate | $KohaDates %] [% reserveloo.reservedate | $KohaDates %] + [% FOREACH cancellation_request IN reserveloo.cancellation_requests.filter_by_current %] + [% cancellation_request.creation_date | $KohaDates %] + [% END %] + [% reserveloo.expirationdate | $KohaDates %] [% INCLUDE 'biblio-title.inc' biblio=reserveloo.biblio link = 1 %] @@ -63,6 +74,12 @@ [% END %] + [% IF table_name == 'holdscr' %] +
    + + +
    + [% END %]