From 0f46c94b4e6ab5e1bba7f49624b40129d2b2a0bb Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 22 May 2013 16:12:43 -0400 Subject: [PATCH] Bug 10314 - CanItemBeReserved does not respect the holds policies CanItemBeReserved will return 1 as long as the circulation rules have a non-zero number of holds allowed and the patron hasn't reached his or her "Holds allowed" count. However, the subroutine completely ignores the holds policies which would contravene reserving the item even if the patron has not reached the maximum holds allowed count. Test Plan: 1) Place an item on hold for a patron 2) Clear any existing hold policies 3) Set the appropriate circ rule so that the patron should be allowed 4) Attempt to place am item-level hold for this item/patron, it should succeed 5) Create a hold policy rule that would stop this patron from placing a hold on this item 6) Attempt to place an item-level hold on this item/patron, it should fail, but instead it will succeed 7) Apply this patch 8) Repeat step 6, this time you should be unable to place a specific hold on this item --- C4/Reserves.pm | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index c8b0cdd..a2aba81 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -427,8 +427,34 @@ sub CanItemBeReserved{ # we retrieve borrowers and items informations # my $item = GetItem($itemnumber); my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); - - # we retrieve user rights on this itemtype and branchcode + + + # Before we check too see if the borrower has exceed the + # maximum number of holds allowed for this itemtype, + # we need to check to see if *any* holds are allowed + # for this patron/itemtype as determined by the holds policy + my $holds_policy = GetBranchItemRule( + $controlbranch eq "ItemHomeLibrary" + ? $item->{homebranch} + : $borrower->{branchcode}, + + $item->{itype} + ); + + if ( $holds_policy->{holdallowed} == 0 ) { + + # If holdallowed is 0, we can quit right here + return 0; + } + elsif ( $holds_policy->{holdallowed} == 1 ) { + + # If it's 1, then only patrons from the item's home library may put this book on hold. + return 0 unless ( $borrower->{'branchcode'} eq $item->{'homebranch'} ); + } + + # If we've gotten this far, the holds policy does not prevent the patron + # from placing this hold. We now need to see if the patron has exceeded + # the maximum number of holds allowed for this itemtype based on the patrons my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed FROM issuingrules WHERE (categorycode in (?,'*') ) -- 1.7.2.5