Bug 11258: fix another case where holds queue made transfer requests that contradict...
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 15 Nov 2013 16:29:23 +0000 (08:29 -0800)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 13 Aug 2014 14:30:02 +0000 (10:30 -0400)
This patch fixes a problem where the holds queue generator
was making requests where the pickup library is the
same as the item's library but not the patron's branch,
even if there is a "Default holds policy by item type" rule that states
this item can only fill holds for patrons of the same library as the
item.

Test Plan:
1) Create a test record with 2 items with different itemtypes
2) Set the Default holds policy by item type for the first
   item to "From any library"
3) Set the Default holds policy by item type for the second
   item to "From home library"
4) Place a record level hold for a patron from another library,
   but for pickup at the same library as the item is from
5) Rebuild the holds queue
6) View the holds queue, note the item is listed, though this
   patron cannot place a hold on this item
7) Apply this patch
8) Repeat step 5, note the hold is no longer in the queue

Signed-off-by: Liz Rea <liz@catalyst.net.nz>
automated tests pass, functional tests pass. Bug replicated, eradicated by patch.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
I finally managed to reproduce this, patch works as described.
Passes tests and QA script, provided tests fail without patch, but
succeed with the patch.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 79660377470e8d6ba9057eb59645886410852c92)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

C4/HoldsQueue.pm
t/db_dependent/HoldsQueue.t

index 20fa482..1c09d6e 100755 (executable)
@@ -427,7 +427,6 @@ sub MapItemsToHoldRequests {
                 }
             }
             $holdingbranch = $pickup_branch;
-            $itemnumber ||= $holding_branch_items->[0]->{itemnumber};
         }
         elsif ($transport_cost_matrix) {
             $pull_branches = [keys %items_by_branch];
@@ -462,6 +461,7 @@ sub MapItemsToHoldRequests {
                 $holdingbranch ||= $branch;
                 foreach my $item (@$holding_branch_items) {
                     next if $pickup_branch ne $item->{homebranch};
+                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
 
                     $itemnumber = $item->{itemnumber};
                     $holdingbranch = $branch;
@@ -471,7 +471,7 @@ sub MapItemsToHoldRequests {
 
             unless ( $itemnumber ) {
                 foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
-                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $pickup_branch eq $current_item->{homebranch} ) ) {
+                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
                         $itemnumber = $current_item->{itemnumber};
                         last; # quit this loop as soon as we have a suitable item
                     }
index b2a6802..9424dce 100755 (executable)
@@ -12,7 +12,7 @@ use C4::Context;
 
 use Data::Dumper;
 
-use Test::More tests => 19;
+use Test::More tests => 20;
 
 use C4::Branch;
 use C4::ItemType;
@@ -285,8 +285,9 @@ $dbh->do("DELETE FROM default_circ_rules");
 $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 1 )");
 C4::HoldsQueue::CreateQueue();
 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
-ok( @$holds_queue == 1, "Holds queue filling correct number for default holds policy 'from home library'" );
-ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling correct hold for default holds policy 'from home library'");
+ok( @$holds_queue == 2, "Holds queue filling correct number for default holds policy 'from home library'" );
+ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'");
+ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
 
 $dbh->do("DELETE FROM default_circ_rules");
 $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");