From 0e2ecaec2dd4181027897de2657fe2565b69b0e6 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 15 Mar 2024 11:35:38 +0000 Subject: [PATCH] Bug 35944: (QA follow-up) Check if there are bookings before other calculations --- C4/Circulation.pm | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e57e634d3c9..9e6a64817df 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3121,18 +3121,21 @@ sub CanBookBeRenewed { } # CHECK FOR BOOKINGS - my $startdate = - ( C4::Context->preference('RenewalPeriodBase') eq 'date_due' ) - ? dt_from_string( $issue->date_due, 'sql' ) - : dt_from_string(); - my $datedue = CalcDateDue( $startdate, $item->effective_itemtype, $branchcode, $patron, 'is a renewal' ); - if ( - my $booking = $item->find_booking( - { checkout_date => $startdate, due_date => $datedue, patron_id => $patron->borrowernumber } - ) - ) - { - return ( 0, 'booked' ) unless ( $booking->patron_id == $patron->borrowernumber ); + if( $item->bookings->count ){ + my $startdate = + ( C4::Context->preference('RenewalPeriodBase') eq 'date_due' ) + ? dt_from_string( $issue->date_due, 'sql' ) + : dt_from_string(); + my $datedue = CalcDateDue( $startdate, $item->effective_itemtype, $branchcode, $patron, 'is a renewal' ); + if ( + my $booking = $item->find_booking( + { checkout_date => $startdate, due_date => $datedue, patron_id => $patron->borrowernumber } + ) + ) + { + return ( 0, 'booked' ) unless ( $booking->patron_id == $patron->borrowernumber ); + } + } if ( $auto_renew eq 'auto_too_soon' ) { -- 2.30.2