From 48f9867203e01830a5c5643c5add4a44faff70cd 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 Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e57e634d3c..9e6a64817d 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.39.5