From ed5a7cf35ac244cecea6961ebb6a5088e11c8b5d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 15 Mar 2019 19:24:19 -0300 Subject: [PATCH] Bug 20728: Proof that there is no cheating To make sure the replacing code will acchieve the same things as the actual one, we replace the raw SQL query with the DBIC version of it. Then the tests will show us that they are equivalent. Test plan: Apply only this patch, run the tests, confirm they pass. Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Acquisition.pm | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 183ff6a128..ce045197ec 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1284,30 +1284,17 @@ Returns a reference-to-hash describing the last order received for a subscriptio sub GetLastOrderReceivedFromSubscriptionid { my ( $subscriptionid ) = @_; - my $dbh = C4::Context->dbh; - my $query = qq| - SELECT * FROM aqorders - LEFT JOIN subscription - ON ( aqorders.subscriptionid = subscription.subscriptionid ) - WHERE aqorders.subscriptionid = ? - AND aqorders.datereceived = - ( - SELECT MAX( aqorders.datereceived ) - FROM aqorders - LEFT JOIN subscription - ON ( aqorders.subscriptionid = subscription.subscriptionid ) - WHERE aqorders.subscriptionid = ? - AND aqorders.datereceived IS NOT NULL - ) - ORDER BY ordernumber DESC - LIMIT 1 - |; - my $result_set = - $dbh->selectall_arrayref( $query, { Slice => {} }, $subscriptionid, $subscriptionid ); - - # result_set assumed to contain 1 match - return $result_set->[0]; - + my $lastOrderReceived = Koha::Acquisition::Orders->search( + { + subscriptionid => $subscriptionid, + datereceived => { '!=' => undef } + }, + { + order_by => + [ { -desc => 'datereceived' }, { -desc => 'ordernumber' } ] + } + ); + return $lastOrderReceived->count ? $lastOrderReceived->next->unblessed : undef; } #------------------------------------------------------------# -- 2.11.0