Bug 2394: Use syspref canreservefromotherbranches in CanItemBeReserved
authorJulian Maurice <julian.maurice@biblibre.com>
Tue, 9 Jul 2013 09:48:23 +0000 (11:48 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 9 Aug 2013 17:55:32 +0000 (17:55 +0000)
If IndependentBranches is ON, patrons are not allowed to place
hold requests on items whose owning library is different from
the patron's home library, *unless* the canreservefromotherbranches
system preference is also ON.

The patch implements the intended behavior; without it, IndependentBranches
and canreservefromotherbranches were not consulted during the
item holdability check.

To test:

[1] Have IndependentBranches ON and canreservefromotherbranches
    OFF.  Make sure that the circulation rules are set up to
    permit patrons to place hold requests in general.
[2] In the OPAC, log in as a patron from library A, and try placing
    a hold on an item from library B.  The patron will be able to
    place the request.
[3] Cancel the request.
[4] Apply the patch.
[5] Try placing the same hold request.  This time, the request should
    be forbidden.
[6] Turn on canreservefromotherbranches.
[7] Try placing the hold request.  This time, it should go through.
[8] Cancel the request.
[9] Turn off IndependentBranches.
[10] Try placing the hold request and verify that it is permitted.
[10]

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Reserves.pm

index 1f89127..0291def 100644 (file)
@@ -510,11 +510,22 @@ sub CanItemBeReserved{
     }
     
     # we check if it's ok or not
-    if( $reservecount < $allowedreserves ){
-        return 1;
-    }else{
+    if( $reservecount >= $allowedreserves ){
         return 0;
     }
+
+    # If reservecount is ok, we check item branch if IndependentBranches is ON
+    # and canreservefromotherbranches is OFF
+    if ( C4::Context->preference('IndependentBranches')
+        and !C4::Context->preference('canreservefromotherbranches') )
+    {
+        my $itembranch = $item->{homebranch};
+        if ($itembranch ne $borrower->{branchcode}) {
+            return 0;
+        }
+    }
+
+    return 1;
 }
 #--------------------------------------------------------------------------------
 =head2 GetReserveCount