From b936f0857df045322405a20b425a550cd419add6 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 2 Apr 2021 14:29:19 +0000 Subject: [PATCH] Bug 28078: Add 'ignore_hold_counts' param to CanItemBeReserved MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds an optional param 'ignore_hold_counts' to the routine, while still forbidding holds when 0 are allowed To test: 1 - prove -v t/db_dependent/Holds.t Signed-off-by: David Nind JK: Commit message amended: Fixed title formatting Signed-off-by: Joonas Kylmälä Signed-off-by: Jonathan Druart (cherry picked from commit d3adcec676f97a1456dbb072479a99f7224e724c) Signed-off-by: Fridolin Somers (cherry picked from commit da72406fa52fe44574d8a64eeca1d8942cc86e99) Signed-off-by: Andrew Fuerste-Henry --- C4/Reserves.pm | 15 +++++++++------ t/db_dependent/Holds.t | 8 +++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 497f53fc64..9367e836d3 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -333,9 +333,12 @@ sub CanBookBeReserved{ $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode, $params) if ($canReserve->{status} eq 'OK') { #We can reserve this Item! } - current params are 'ignore_found_holds' - if true holds that have been trapped are not counted + current params are: + 'ignore_found_holds' - if true holds that have been trapped are not counted toward the patron limit, used by checkHighHolds to avoid counting the hold we will fill with the current checkout against the high holds threshold + 'ignore_hold_counts' - we use this routine to check if an item can fill a hold - on this case we + should not check if there are too many holds as we only csre about reservability @RETURNS { status => OK }, if the Item can be reserved. { status => ageRestricted }, if the Item is age restricted for this borrower. @@ -434,7 +437,7 @@ sub CanItemBeReserved { $search_params->{found} = undef if $params->{ignore_found_holds}; my $holds = Koha::Holds->search($search_params); - if ( defined $holds_per_record && $holds_per_record ne '' + if (!$params->{ignore_hold_counts} && defined $holds_per_record && $holds_per_record ne '' && $holds->count() >= $holds_per_record ) { return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record }; } @@ -444,7 +447,7 @@ sub CanItemBeReserved { reservedate => dt_from_string->date }); - if ( defined $holds_per_day && $holds_per_day ne '' + if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '' && $today_holds->count() >= $holds_per_day ) { return { status => 'tooManyReservesToday', limit => $holds_per_day }; @@ -477,8 +480,8 @@ sub CanItemBeReserved { } # we check if it's ok or not - if ( defined $allowedreserves && $allowedreserves ne '' - && $reservecount >= $allowedreserves ) { + if ( defined $allowedreserves && $allowedreserves ne '' + && $reservecount >= $allowedreserves && (!$params->{ignore_hold_counts} || $allowedreserves == 0 ) ) { return { status => 'tooManyReserves', limit => $allowedreserves }; } @@ -490,7 +493,7 @@ sub CanItemBeReserved { rule_name => 'max_holds', } ); - if ( $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) { + if (!$params->{ignore_hold_counts} && $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) { my $total_holds_count = Koha::Holds->search( { borrowernumber => $borrower->{borrowernumber} diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 26a9c05af6..b98292afc8 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 67; +use Test::More tests => 69; use MARC::Record; use C4::Biblio; @@ -384,6 +384,10 @@ is( CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves', "cannot request item if policy that matches on item-level item type forbids it" ); +is( + CanItemBeReserved( $borrowernumbers[0], $item->itemnumber, undef, { ignore_hold_counts => 1 })->{status}, 'tooManyReserves', + "cannot request item if policy that matches on item-level item type forbids it even if ignoring counts" +); $item->itype('CAN')->store; ok( @@ -489,6 +493,8 @@ my $res_id = AddReserve( is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, 'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber, undef, { ignore_hold_counts => 1 } )->{status}, + 'OK', 'Patron can reserve item if checking policy but not counts' ); #results should be the same for both ReservesControlBranch settings t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); -- 2.39.5