From f847cfdd7efa8dcf13985409dcd333a933dbe416 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 6 Nov 2019 14:59:03 +0000 Subject: [PATCH] Bug 23964: (follow-up) Add comments and improve readability Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- C4/Reserves.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index cf1da8be10..0f7e58ac5f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -174,7 +174,23 @@ sub AddReserve { # of the document, we force the value $priority and $found . if ( $checkitem and not C4::Context->preference('ReservesNeedReturns') ) { my $item = Koha::Items->find( $checkitem ); # FIXME Prevent bad calls - if ( !$item->onloan && $item->holdingbranch eq $branch && ( $item->damaged && C4::Context->preference('AllowHoldsOnDamagedItems') || !$item->damaged ) && !$item->get_transfer && !$item->holds->count ) { + + if ( + # If item is already checked out, it cannot be set waiting + !$item->onloan + + # The item can't be waiting if it needs a transfer + && $item->holdingbranch eq $branch + + # Similarly, if in transit it can't be waiting + && !$item->get_transfer + + # If we can't hold damaged items, and it is damaged, it can't be waiting + && ( $item->damaged && C4::Context->preference('AllowHoldsOnDamagedItems') || !$item->damaged ) + + # Lastly, if this already has holds, we shouldn't make it waiting for the new hold + && !$item->holds->count ) + { $priority = 0; $found = 'W'; } -- 2.39.5