From 87917a8d20beb7cc0c3c8c2d5f53afb1f9b44c5e 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 10f4be3..a0796ff 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -354,7 +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; + $holds_per_day = $rights->{holds_per_day}; } else { $ruleitemtype = '*'; @@ -377,8 +377,10 @@ sub CanItemBeReserved { reservedate => dt_from_string->date }); - if ( $holds_per_day > 0 - && $today_holds->count() >= $holds_per_day ) { + if ( defined $holds_per_day && + ( ( $holds_per_day > 0 && $today_holds->count() >= $holds_per_day ) + or ( $holds_per_day == 0 ) ) + ) { return "tooManyReservesToday"; } -- 2.7.4