From 07f83daf376d93d10512a28041d2bc7f3709b662 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 19 Jul 2017 18:14:19 -0300 Subject: [PATCH] Bug 15486: Extend CanItemBeReserved so it handles daily holds limits This patch implements the required changes in C4::Reserves::CanItemBeReserved so it implements a daily limit on holds. It returns the 'tooManyReservesToday' string if the policy doesn't allow placing the hold. It returns 'OK' (current behaviour) otherwise. To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/db_dependent/Holds.t => FAIL: Tests fail because the error condition is not making CanItemBeReserved return the desired error code. - Apply this patch - Run: k$ prove t/db_dependent/Holds.t => SUCCESS: Tests pass! - Sign off :-D --- C4/Reserves.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 521b072368..5cf08b40e3 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -303,6 +303,7 @@ sub CanItemBeReserved { my $ruleitemtype; # itemtype of the matching issuing rule my $allowedreserves = 0; # Total number of holds allowed across all records my $holds_per_record = 1; # Total number of holds allowed for this one given record + my $holds_per_day = 0; # Total number of holds allowed per day for the given patron # we retrieve borrowers and items informations # # item->{itype} will come for biblioitems if necessery @@ -353,6 +354,7 @@ sub CanItemBeReserved { $ruleitemtype = $rights->{itemtype}; $allowedreserves = $rights->{reservesallowed}; $holds_per_record = $rights->{holds_per_record}; + $holds_per_day = $rights->{holds_per_day} // 0; } else { $ruleitemtype = '*'; @@ -370,6 +372,16 @@ sub CanItemBeReserved { return "tooManyHoldsForThisRecord"; } + my $today_holds = Koha::Holds->search({ + borrowernumber => $borrowernumber, + reservedate => dt_from_string->date + }); + + if ( $holds_per_day > 0 + && $today_holds->count() >= $holds_per_day ) { + return "tooManyReservesToday"; + } + # we retrieve count $querycount .= "AND $branchfield = ?"; @@ -2148,7 +2160,7 @@ sub GetHoldRule { my $sth = $dbh->prepare( q{ - SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record + SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record, holds_per_day FROM issuingrules WHERE (categorycode in (?,'*') ) AND (itemtype IN (?,'*')) -- 2.14.1