From 0c1fc78095fcad694042db3d31e3e31be8dd18c9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 3 May 2021 11:42:47 -0300 Subject: [PATCH] Bug 28273: Multi-hold should not offer invalid pickup locations This patch makes the multi-hold page offer only valid pickup locations for the selected biblios. Prior to this, all system-wide pickup locations were offered. To test: 1. Set 'Hold pickup library match' to 'Item's home branch' so we put a constraint on the valid pickup locations for easier testing. 2. Choose two or more biblios from a search, which contain in total 2 or 3 item home branches. 3. Click 'Place hold' 4. Choose a patron => FAIL: The dropdown offers all system's pickup locations 5. Apply this patches 6. Reload the page => SUCCESS: Only valid pickup locations are offered 7. Sign off :-D --- .../prog/en/modules/reserve/request.tt | 44 +++++++++++++++++-- reserve/placerequest.pl | 7 +-- reserve/request.pl | 14 ++++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 211b9904edc..73b50fc0bb5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1,6 +1,7 @@ [% USE raw %] [% USE To %] [% USE Asset %] +[% USE JSON.Escape %] [% USE Koha %] [% USE KohaDates %] [% USE Branches %] @@ -414,6 +415,7 @@ [% IF ( multi_hold ) %] + [% FOREACH biblioloo IN biblioloop %] @@ -454,7 +456,10 @@ [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %] [% ELSE %] @@ -759,6 +764,7 @@ [% END %] Priority Information + Pickup location [% FOREACH biblioloo IN biblioloop %] [% IF ( biblioloo.warn ) %] @@ -822,6 +828,18 @@ [% END %] [% END %] + + + [% END # /FOREACH biblioloo %] @@ -1252,10 +1270,30 @@ templateResult: display_pickup_location }); }); + $("#pickup_multi").select2({ - width: 'style', - allowClear: false + width: '30%', + allowClear: true + }); + + $('.multi_pickup_select').select2({ + width: '100%', + allowClear: true }); + + $("#pickup_multi").on("change", function() { + var selection = $(this).val(); + if ( selection != '' ) { + $(".multi_pickup_select").each(function() { + var valid_pickup_locations = $(this).data('pickup-locations'); + if ( valid_pickup_locations.includes(selection) ) { + $(this).val(selection); + $(this).trigger("change"); + } + }); + } + }); + $("#pickup").each( function () { var this_dropdown = $(this); var patron_id = $(this).data('patron-id'); diff --git a/reserve/placerequest.pl b/reserve/placerequest.pl index 9e83661c337..63555944a59 100755 --- a/reserve/placerequest.pl +++ b/reserve/placerequest.pl @@ -67,8 +67,9 @@ my %bibinfos = (); my @biblionumbers = split '/', $biblionumbers; foreach my $bibnum (@biblionumbers) { my %bibinfo = (); - $bibinfo{title} = $input->param("title_$bibnum"); - $bibinfo{rank} = $input->param("rank_$bibnum"); + $bibinfo{title} = $input->param("title_$bibnum"); + $bibinfo{rank} = $input->param("rank_$bibnum"); + $bibinfo{pickup} = $input->param("pickup_$bibnum"); $bibinfos{$bibnum} = \%bibinfo; } @@ -128,7 +129,7 @@ if ( $type eq 'str8' && $borrower ) { if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) { AddReserve( { - branchcode => $branch, + branchcode => $bibinfo->{pickup}, borrowernumber => $borrower->{'borrowernumber'}, biblionumber => $biblionumber, priority => $bibinfo->{rank}, diff --git a/reserve/request.pl b/reserve/request.pl index f9847ada773..bf13c3dfb2b 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -286,6 +286,13 @@ $template->param( # FIXME launch another time GetMember perhaps until (Joubu: Why?) my $patron = Koha::Patrons->find( $borrowernumber_hold ); +if ( $patron && $multi_hold ) { + my @multi_pickup_locations = + Koha::Biblios->search( { biblionumber => \@biblionumbers } ) + ->pickup_locations( { patron => $patron } ); + $template->param( multi_pickup_locations => \@multi_pickup_locations ); +} + my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); my $wants_check; @@ -737,6 +744,13 @@ foreach my $biblionumber (@biblionumbers) { $template->param( reserveloop => \@reserveloop ); } + if ( $patron ) { + # Add the valid pickup locations + my @pickup_locations = $biblio->pickup_locations({ patron => $patron }); + $biblioloopiter{pickup_locations} = \@pickup_locations; + $biblioloopiter{pickup_locations_codes} = [ map { $_->branchcode } @pickup_locations ]; + } + push @biblioloop, \%biblioloopiter; } -- 2.31.1