From b0f49d5dafa4e2dcc05e1e85c13cde3b66f041f5 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Wed, 5 Oct 2022 16:04:59 +0000 Subject: [PATCH] Bug 31692: Allow librarians to change hold type in staff client To test: 1. Apply patch 2. Add item level hold to a record/item, make sure patron has no other holds on that record 3. Go to /cgi-bin/koha/reserve/request.pl?biblionumber=xxx where xxx is the record you placed the hold for 4. Under "Existing holds" table, in "Details" column you should see "Only item " dropdown 5. Select "Next available" from the dropdown 6. Click Update hold(s) 7. Observe dropdown is gone and cell value has changed from "Only item " to "Next available" 8. Cancel the hold and add two item level holds for the same patron 9. Under "Existing holds" table, in "Details" column you should see "Only item ", but no select dropdown Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- .../prog/en/includes/holds_table.inc | 20 +++++++++++++++++++ reserve/modrequest.pl | 16 ++++++++++++++- reserve/request.pl | 11 ++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc index 035ee0aa06..543c027957 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -176,6 +176,7 @@ [%- ELSE -%] [%- IF ( hold.item_level_hold ) -%] + [%- IF ! hold.change_hold_type_allowed -%] Only item [%- IF ( hold.barcodenumber ) -%] @@ -185,6 +186,25 @@ No barcode [%- END -%] + [%- ELSE -%] + + [%- IF ( hold.barcodenumber ) -%] + + [%- END -%] + [%- IF hold.itemtype -%] + Next available [% ItemTypes.GetDescription( hold.itemtype ) | html %] item + [%- ELSE -%] + Next available + [%- END -%] + [%- END -%] [%- ELSE -%] [%- IF hold.itemtype -%] diff --git a/reserve/modrequest.pl b/reserve/modrequest.pl index 3e9e5631b8..e41e999d64 100755 --- a/reserve/modrequest.pl +++ b/reserve/modrequest.pl @@ -88,7 +88,21 @@ else { } else { $_->rethrow; } - } + }; + + if ( $query->param( "change_hold_type_" . $reserve_id[$i] ) ) { + my $hold = Koha::Holds->find( $reserve_id[$i] ); + + try { + $hold->change_type; + } catch { + if ($_->isa('Koha::Exceptions::Hold::CannotChangeHoldType')){ + warn $_; + } else { + $_->rethrow; + } + } + }; } my @biblio_ids = uniq @biblionumber; Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( diff --git a/reserve/request.pl b/reserve/request.pl index 36af34399c..e9f420ec94 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -579,6 +579,13 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) $template->param( always_show_holds => $always_show_holds ); my $show_holds_now = $input->param('show_holds_now'); unless( (defined $always_show_holds && $always_show_holds eq 'DONT') && !$show_holds_now ){ + my $holds_count_per_patron = { map { $_->{borrowernumber} => $_->{hold_count} } + @{ Koha::Holds->search( { biblionumber=> $biblionumber }, { + select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ], + as => [ qw( borrowernumber hold_count ) ], + group_by => [ qw( borrowernumber ) ] } + )->unblessed + } }; my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list; foreach my $res ( sort { @@ -630,6 +637,10 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) $reserve{non_priority} = $res->non_priority(); $reserve{object} = $res; + if ( $holds_count_per_patron->{ $reserve{'borrowernumber'} } == 1 ) { + $reserve{'change_hold_type_allowed'} = 1; + } + push( @reserveloop, \%reserve ); } } -- 2.39.5