From 8a955f6ff864af5f50664c396c3c3a89edc204b7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 27 May 2022 12:52:28 +0000 Subject: [PATCH] Bug 30860: Return all items from CanBookBeReserved on request.pl This patch requests all item values from CanBookBeReserved on request.pl Before this we either: - Looped every item to find out that book could not be reserved - Looped until we found an item that could be reserved, then looped all items to get statuses In the worst case we avoid double processing a single item, in the best case we avoid double processing all items (if only last on record is holdable) To test: 1 - Find a record in staff client with several items 2 - Set AllowHoldsOnDamagedItems to 'Dont allow' 3 - Add a damaged item to record 4 - Set a hold rule to only allow holds form homebranch and ensure record has items from other branches 5 - Setup things to prevent more items from being held 6 - Attempt hold for patron 7 - Note item statuses 8 - Apply patch 9 - Confirm statuses are as they were before Signed-off-by: Andrew Fuerste-Henry --- reserve/request.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reserve/request.pl b/reserve/request.pl index e5faf1426a..f918ddc139 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -33,7 +33,7 @@ use List::MoreUtils qw( uniq ); use Date::Calc qw( Date_to_Days ); use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); -use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord ItemsAnyAvailableAndNotRestricted CanItemBeReserved IsAvailableForItemLevelRequest ); +use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest ); use C4::Items qw( get_hostitemnumbers_of ); use C4::Koha qw( getitemtypeimagelocation ); use C4::Serials qw( CountSubscriptionFromBiblionumber ); @@ -308,9 +308,10 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) $biblioloopiter{object} = $biblio; + my $canReserve; if ( $patron ) { { # CanBookBeReserved - my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber ); + $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber, undef,{ return_all_items => 1 }); if ( $canReserve->{status} eq 'OK' ) { #All is OK and we can continue @@ -486,7 +487,7 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) $item->{'holdallowed'} = $branchitemrule->{'holdallowed'}; - my $can_item_be_reserved = CanItemBeReserved( $patron, $item_object )->{status}; + my $can_item_be_reserved = $canReserve->{$item_object->itemnumber}->{status}; $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' ); $item->{not_holdable} ||= 'notforloan' if ( $item->{notforloanitype} || $item->{notforloan} > 0 ); -- 2.30.2