Bug 14237: Database updates
[srvgit] / C4 / HoldsQueue.pm
index d4380cc..3774214 100644 (file)
@@ -371,24 +371,38 @@ sub GetItemsAvailableToFillHoldRequestsForBib {
 =cut
 
 sub _checkHoldPolicy {
-    my ($item, $request) = @_;
+    my ( $item, $request ) = @_;
 
-    return 0 unless $item->{holdallowed};
-    return 0 if $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch};
+    return 0 unless $item->{holdallowed} ne 'not_allowed';
 
-    my $library = Koha::Libraries->find($item->{homebranch});
+    return 0
+      if $item->{holdallowed} eq 'from_home_library'
+      && $item->{homebranch} ne $request->{borrowerbranch};
 
-    return 0 if $item->{'holdallowed'} == 3 && !$library->validate_hold_sibling({branchcode => $request->{borrowerbranch}});
+    return 0
+      if $item->{'holdallowed'} eq 'from_local_hold_group'
+      && !Koha::Libraries->find( $item->{homebranch} )
+              ->validate_hold_sibling( { branchcode => $request->{borrowerbranch} } );
 
     my $hold_fulfillment_policy = $item->{hold_fulfillment_policy};
 
-    return 0 if $hold_fulfillment_policy eq 'holdgroup' && !$library->validate_hold_sibling({branchcode => $request->{branchcode}});
-    return 0 if $hold_fulfillment_policy eq 'homebranch' && $request->{branchcode} ne $item->{$hold_fulfillment_policy};
-    return 0 if $hold_fulfillment_policy eq 'holdingbranch' && $request->{branchcode} ne $item->{$hold_fulfillment_policy};
+    return 0
+      if $hold_fulfillment_policy eq 'holdgroup'
+      && !Koha::Libraries->find( $item->{homebranch} )
+            ->validate_hold_sibling( { branchcode => $request->{branchcode} } );
 
-    my $patronLibrary = Koha::Libraries->find($request->{borrowerbranch});
+    return 0
+      if $hold_fulfillment_policy eq 'homebranch'
+      && $request->{branchcode} ne $item->{$hold_fulfillment_policy};
 
-    return 0 if $hold_fulfillment_policy eq 'patrongroup' && !$patronLibrary->validate_hold_sibling({branchcode => $request->{branchcode}});
+    return 0
+      if $hold_fulfillment_policy eq 'holdingbranch'
+      && $request->{branchcode} ne $item->{$hold_fulfillment_policy};
+
+    return 0
+      if $hold_fulfillment_policy eq 'patrongroup'
+      && !Koha::Libraries->find( $request->{borrowerbranch} )
+              ->validate_hold_sibling( { branchcode => $request->{branchcode} } );
 
     return 1;
 
@@ -530,7 +544,7 @@ sub MapItemsToHoldRequests {
     # group available items by branch
     my %items_by_branch = ();
     foreach my $item (@$available_items) {
-        next unless $item->{holdallowed};
+        next unless $item->{holdallowed} ne 'not_allowed';
 
         push @{ $items_by_branch{ $item->{holdingbranch} } }, $item
           unless exists $allocated_items{ $item->{itemnumber} };