From a35dd76ed0465990a949cb9b89d394b4918949e6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 14 May 2013 14:59:07 -0500 Subject: [PATCH] Bug 10243: prevent holds queue from making transfer requests that contradict library holds policy For some reason MapItemsToHoldRequests will, as a last ditch effort, grab what seems to be an arbitrary available item to fill a hold request, even if it will violate the circulation rules for holds. In other words, even if an item matches a "Holds policy by item type" that says "From home library", a request to transfer that item to another library will be added to the holds queue! Test Plan: 1) Create a record with a an item at BranchA of item type BOOK 2) Set the holds policy such that itemtype BOOK for BranchA is set to "From home library" 3) Place a bib-level hold request for a patron with a pickup at BranchB 4) Run build_holds_queue.pl 5) You should now see a request for that item to be transfered to BranchB, even though the rules should not allow this. 6) Apply this patch 7) Run build_holds_queue.pl again 8) View the holds queue again, that request should no longer exist Signed-off-by: Heather Braum Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton (cherry picked from commit 78d27ad5393308ce097db9aa0dfe5c28aa40a516) Signed-off-by: Tomas Cohen Arazi --- C4/HoldsQueue.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index eff3148d40..64e942af4a 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -338,7 +338,7 @@ sub GetItemsAvailableToFillHoldRequestsForBib { my @items = grep { ! scalar GetTransfers($_->{itemnumber}) } @$itm; return [ grep { my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype}); - $_->{holdallowed} = $rule->{holdallowed} != 0 + $_->{holdallowed} = $rule->{holdallowed}; } @items ]; } @@ -469,8 +469,15 @@ sub MapItemsToHoldRequests { last PULL_BRANCHES; } } - $itemnumber ||= $items_by_branch{$holdingbranch}->[0]->{itemnumber} - if $holdingbranch; + + unless ( $itemnumber ) { + foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) { + if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $pickup_branch eq $current_item->{homebranch} ) ) { + $itemnumber = $current_item->{itemnumber}; + last; # quit this loop as soon as we have a suitable item + } + } + } } if ($itemnumber) { -- 2.39.5