From ad0e28cce141a1eb63ea169df947aab475893d3a Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Thu, 13 Nov 2025 12:36:11 +0000 Subject: [PATCH] Bug 20125: (QA follow-up) change from SQL query to Koha::Objects --- misc/cronjobs/ordersClaim.pl | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/misc/cronjobs/ordersClaim.pl b/misc/cronjobs/ordersClaim.pl index 280f7a3fba..d010812576 100755 --- a/misc/cronjobs/ordersClaim.pl +++ b/misc/cronjobs/ordersClaim.pl @@ -39,6 +39,7 @@ use Pod::Usage; use C4::Letters qw( GetPreparedLetter EnqueueLetter ); use Koha::Acquisition::Orders; +use Koha::DateUtils qw( dt_from_string output_pref ); =head1 NAME @@ -114,23 +115,25 @@ while ( my ( $basketno, $orderids ) = each %$baskets_orders ) { $delay = $bookseller->deliverytime || 0; } - my $dbh = C4::Context->dbh; - - my $orderids_str = join( ',', ('?') x @$orderids ); - my $orders = $dbh->selectall_arrayref( - qq{ - SELECT aqorders.*, aqbasket.*, biblio.*, - COUNT(aqorders_claims.claimed_on) AS claims_count, - MAX(aqorders_claims.claimed_on) AS last_claim - FROM aqorders - LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber - LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno - LEFT JOIN aqorders_claims ON aqorders.ordernumber = aqorders_claims.ordernumber - WHERE aqorders.ordernumber IN ($orderids_str) - HAVING claims_count <= $max_claims - AND (last_claim IS NULL or last_claim <= DATE_SUB(CAST(now() AS date),INTERVAL $claimed_for DAY)) - }, { Slice => {} }, @$orderids - ); + my $orders = []; + my $order_objects = Koha::Acquisition::Orders->search( { ordernumber => { -in => $orderids } } ); + while ( my $order = $order_objects->next ) { + my $claims_count = $order->claims_count; + my $last_claim = dt_from_string( $order->claimed_date ); + + next if $claims_count > $max_claims; + next if $last_claim && $last_claim > dt_from_string->subtract( days => $claimed_for ); + + my $result = { + %{ $order->unblessed }, + %{ $order->basket->unblessed }, + %{ $order->biblio->unblessed }, + claims_count => $claims_count, + last_claim => $last_claim, + }; + + push @$orders, $result; + } next unless @$orders; -- 2.39.5