From da72406fa52fe44574d8a64eeca1d8942cc86e99 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 --- 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 dfed93347d..8d777771d9 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -347,9 +347,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. @@ -454,7 +457,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 }; } @@ -464,7 +467,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 }; @@ -497,8 +500,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 }; } @@ -510,7 +513,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 3e736f6774..6f5497dd67 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 => 68; +use Test::More tests => 70; use MARC::Record; use C4::Biblio; @@ -386,6 +386,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( @@ -491,6 +495,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