From f2fca4064f676394b0eb310a892058eb90589f8d 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 value has changed from "Only item " to "Next available" 8. Cancel the hold and add two item level holds 9. Under "Existing holds" table, in "Details" column you should see "Only item ", but no select dropdown --- .../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 536bd16484..a379d41816 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -166,6 +166,7 @@ [%- ELSE -%] [%- IF ( hold.item_level_hold ) -%] + [%- IF ! hold.change_hold_type_allowed -%] Only item [%- IF ( hold.barcodenumber ) -%] @@ -175,6 +176,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 2c28f2c58f..93abe66a4b 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -593,6 +593,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 { @@ -643,6 +650,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