[Koha-patches] [PATCH] holds policies fixes

Galen Charlton galen.charlton at liblime.com
Fri Jan 30 22:21:29 CET 2009


* use item branch instead of patron's branch to
look up the applicable hold policies - this makes
requesting in the OPAC consistent with the intranet.
* when generating pick list using build_holds_queue.pl, only match items
to patrons if request is allowed.
---
 misc/cronjobs/holds/build_holds_queue.pl |   18 ++++++++++++++----
 opac/opac-reserve.pl                     |    2 +-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl
index e9054da..57e1183 100755
--- a/misc/cronjobs/holds/build_holds_queue.pl
+++ b/misc/cronjobs/holds/build_holds_queue.pl
@@ -108,6 +108,7 @@ priority
 branchcode
 reservedate
 reservenotes
+borrowerbranch
 
 The arrayref is sorted in order of increasing priority.
 
@@ -118,8 +119,10 @@ sub GetPendingHoldRequestsForBib {
 
     my $dbh = C4::Context->dbh;
 
-    my $request_query = "SELECT biblionumber, borrowernumber, itemnumber, priority, branchcode, reservedate, reservenotes
+    my $request_query = "SELECT biblionumber, borrowernumber, itemnumber, priority, reserves.branchcode, 
+                                reservedate, reservenotes, borrowers.branchcode AS borrowerbranch
                          FROM reserves
+                         JOIN borrowers USING (borrowernumber)
                          WHERE biblionumber = ?
                          AND found IS NULL
                          AND priority > 0
@@ -190,7 +193,9 @@ sub GetItemsAvailableToFillHoldRequestsForBib {
     $sth->execute(@params);
 
     my $items = $sth->fetchall_arrayref({});
-    return [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ]; 
+    $items = [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ]; 
+    map { my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype}); $_->{holdallowed} = $rule->{holdallowed}; $rule->{holdallowed} != 0 } @$items;
+    return [ grep { $_->{holdallowed} != 0 } @$items ];
 }
 
 =head2 MapItemsToHoldRequests
@@ -268,7 +273,10 @@ sub MapItemsToHoldRequests {
 
         # look for local match first
         my $pickup_branch = $request->{branchcode};
-        if (exists $items_by_branch{$pickup_branch}) {
+        if (exists $items_by_branch{$pickup_branch} and 
+            not ($items_by_branch{$pickup_branch}->[0]->{holdallowed} == 1 and 
+                 $request->{borrowerbranch} ne $items_by_branch{$pickup_branch}->[0]->{homebranch}) 
+           ) {
             my $item = pop @{ $items_by_branch{$pickup_branch} };
             delete $items_by_branch{$pickup_branch} if scalar(@{ $items_by_branch{$pickup_branch} }) == 0;
             $item_map{$item->{itemnumber}} = { 
@@ -289,7 +297,9 @@ sub MapItemsToHoldRequests {
                 @pull_branches = sort keys %items_by_branch;
             }
             foreach my $branch (@pull_branches) {
-                next unless exists $items_by_branch{$branch};
+                next unless exists $items_by_branch{$branch} and
+                            not ($items_by_branch{$branch}->[0]->{holdallowed} == 1 and 
+                                $request->{borrowerbranch} ne $items_by_branch{$branch}->[0]->{homebranch});
                 my $item = pop @{ $items_by_branch{$branch} };
                 delete $items_by_branch{$branch} if scalar(@{ $items_by_branch{$branch} }) == 0;
                 $item_map{$item->{itemnumber}} = { 
diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index 445da2b..5f22a5a 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -332,7 +332,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
         # If there is no loan, return and transfer, we show a checkbox.
         $item->{notforloan} = $item->{notforloan} || 0;
 
-        my $branchitemrule = GetBranchItemRule( $borr->{'branchcode'}, $item->{'itype'} );
+        my $branchitemrule = GetBranchItemRule( $item->{'homebranch'}, $item->{'itype'} );
         my $policy_holdallowed = 1;
 
         if ( $branchitemrule->{'holdallowed'} == 0 ||
-- 
1.5.5.GIT




More information about the Koha-patches mailing list