From 7c5933c129a98c1eec851646c99d438bff755b7c 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 | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e57e634d3c9..5b90cf0eccd 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3121,29 +3121,31 @@ 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' ) { + if ( $auto_renew eq 'auto_too_soon' ) { - # If its cron, tell it it's too soon for a an auto renewal - return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $cron; + # If its cron, tell it it's too soon for a an auto renewal + return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $cron; - # Check if it's too soon for a manual renewal - my $soonestManual = GetSoonestRenewDate( $patron, $issue ); - if ( $soonestManual > dt_from_string() ) { - return ( 0, "too_soon", { soonest_renew_date => $soonestManual } ) unless $override_limit; + # Check if it's too soon for a manual renewal + my $soonestManual = GetSoonestRenewDate( $patron, $issue ); + if ( $soonestManual > dt_from_string() ) { + return ( 0, "too_soon", { soonest_renew_date => $soonestManual } ) unless $override_limit; + } } } -- 2.30.2