Bug 28078: Add 'ignore_hold_counts' param to CanItemBeReserved
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 <david@davidnind.com> JK: Commit message amended: Fixed title formatting Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
34acb76a21
commit
d3adcec676
2 changed files with 16 additions and 7 deletions
|
@ -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}
|
||||
|
|
|
@ -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' );
|
||||
|
|
Loading…
Reference in a new issue