From 37bb2cc823e4411fa7f63ab705888eb43ec05199 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 4 Apr 2023 04:45:14 +0000 Subject: [PATCH] Bug 33399: [WIP] Improve checks of other items to determine if valid recall This patch employs the following checks to determine if it is valid for a patron to place a recall: - that we don't include items already allocated to a hold (i.e. hold 'is found') when counting for recallable items - that we don't include items that aren't allowed to be recalled (based on the recallsallowed circulation rule) when counting for recallable items Test plan coming --- Koha/Item.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 0d29655938d..b2e688b913c 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1929,12 +1929,27 @@ sub can_be_recalled { return 0 if ( scalar @items == 0 ); my $checked_out_count = 0; + my $recallable_items = scalar @items; foreach (@items) { - if ( Koha::Checkouts->search({ itemnumber => $_->itemnumber })->count > 0 ){ $checked_out_count++; } + my $item_recalls_allowed = Koha::CirculationRules->get_effective_rule({ + branchcode => $branchcode, + categorycode => $patron ? $patron->categorycode : undef, + itemtype => $_->effective_itemtype, + rule_name => 'recalls_allowed', + }); + if ( $item_recalls_allowed->rule_value == 0 ) { + # item is not allowed to be recalled + $recallable_items--; + } elsif ( $_->holds({ found => [ 'W','T','P' ] })->count > 0 ) { + # item is allocated for another hold + $recallable_items--; + } elsif ( Koha::Checkouts->search({ itemnumber => $_->itemnumber })->count > 0 ) { + $checked_out_count++; + } } # can't recall if on shelf recalls only allowed when all unavailable, but items are still available for checkout - return 0 if ( $rule->{on_shelf_recalls} eq 'all' && $checked_out_count < scalar @items ); + return 0 if ( $rule->{on_shelf_recalls} eq 'all' && $checked_out_count < $recallable_items ); # can't recall if no items have been checked out return 0 if ( $checked_out_count == 0 ); -- 2.30.2