From dfd1e7056e3ed5dd117fdfc2160c3dba4c93d9bf 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 --- .../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 d5b9a67a4f..b50246e000 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -168,6 +168,7 @@ [%- ELSE -%] [%- IF ( hold.item_level_hold ) -%] + [%- IF ! hold.change_hold_type_allowed -%] Only item [%- IF ( hold.barcodenumber ) -%] @@ -177,6 +178,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 ec78f683be..bd733dc38e 100755 --- a/reserve/modrequest.pl +++ b/reserve/modrequest.pl @@ -94,7 +94,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 e5faf1426a..6e92d1cf97 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -597,6 +597,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 { @@ -647,6 +654,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.25.1