Bug 26076: (QA Follow up) Prevent error by using a fresh resultset
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 30 Jul 2020 13:35:38 +0000 (09:35 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 24 Aug 2020 08:12:49 +0000 (10:12 +0200)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

members/paycollect.pl

index a8f449e..9ef0053 100755 (executable)
@@ -145,21 +145,27 @@ if ( $selected_accts ) {
     }
     my @acc = split /,/, $selected_accts;
 
-    my $selected_accountlines = Koha::Account::Lines->search(
-        {
-            borrowernumber    => $borrowernumber,
+    my $search_params = {
+        borrowernumber    => $borrowernumber,
             amountoutstanding => { '<>' => 0 },
             accountlines_id   => { 'in' => \@acc },
-        },
+    };
+
+    my @selected_accountlines = Koha::Account::Lines->search(
+        $search_params,
         { order_by => 'date' }
     );
 
-    $total_due = $selected_accountlines->_resultset->get_column('amountoutstanding')->sum();
-
-    @selected_accountlines = $selected_accountlines->as_list;
+    my $sum = Koha::Account::Lines->search(
+        $search_params,
+        {
+            select => [ { sum => 'amountoutstanding' } ],
+            as     => [ 'total_amountoutstanding'],
+        }
+    );
+    $total_due = $sum->_resultset->first->get_column('total_amountoutstanding');
 }
 
-
 if ( $total_paid and $total_paid ne '0.00' ) {
     $total_paid = $total_due if (abs($total_paid - $total_due) < 0.01) && C4::Context->preference('RoundFinesAtPayment');
     if ( $total_paid < 0 or $total_paid > $total_due ) {