From 7fd1e70081c93f9cb1c7e70c1d7833edc769984e Mon Sep 17 00:00:00 2001
From: Arthur Suzuki <arthur.suzuki@biblibre.com>
Date: Tue, 14 May 2019 02:30:26 +0200
Subject: [PATCH] Bug 22806 : CanBookBeReserved and CanItemBeReserved must
 check AllowHoldsOnPatronsPossessions

Test plan :
1 - set AllowHoldsOnPatronsPossessions to "Don't Allow"
2 - Checkout an item to a borrower
3 - Try to reserve an item using ILS-DI WebService -> Will work without complaining.
4 - Cancel the hold and apply patch
5 - Repeat 3 -> Should not place hold and show error "NotHoldable"
---
 C4/Reserves.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 5fc68f1359..bbc27a287f 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -274,6 +274,12 @@ See CanItemBeReserved() for possible return values.
 sub CanBookBeReserved{
     my ($borrowernumber, $biblionumber, $pickup_branchcode) = @_;
 
+    # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set)
+    if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
+        && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) {
+        return { status =>'itemAlreadyOnLoan' };
+    }
+
     my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
     #get items linked via host records
     my @hostitems = get_hostitemnumbers_of($biblionumber);
@@ -336,6 +342,12 @@ sub CanItemBeReserved {
     return { status =>'itemAlreadyOnHold' }
       if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
 
+    # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set)
+    if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
+        && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) {
+        return { status =>'itemAlreadyOnLoan' };
+    }
+
     my $controlbranch = C4::Context->preference('ReservesControlBranch');
 
     my $querycount = q{
-- 
2.11.0