Bug 26076: Sum the amount due in the database query instead of a loop in Perl

This appears to be a bug due to inaccuracies in floating point math. I've been unable to reproduce it on demand. Sometimes when using the "Write off selected" button, Koha will give the error that the payment is more than the amount owed, even though they are the same. The solution I've implemented is to move the summation from Perl code to the database query. This video demonstrates the issue and afterward, shows the error goes away after the patch is applied: https://monosnap.com/file/pG69HC7iI9mU9kkuoCtbkVzVTffKlE

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Verify that "Write off selected" functions as usual

Signed-off-by: Amit Gupta <amit.gupta@informaticsglobal.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 6441296903)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 2e3b3a23fc)

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
This commit is contained in:
Kyle M Hall 2020-07-28 12:49:35 -04:00 committed by Aleisha Amohia
parent 2a48a23c42
commit 6ccd2a55e1
1 changed files with 4 additions and 3 deletions

View File

@ -143,7 +143,7 @@ if ( $selected_accts ) {
}
my @acc = split /,/, $selected_accts;
@selected_accountlines = Koha::Account::Lines->search(
my $selected_accountlines = Koha::Account::Lines->search(
{
borrowernumber => $borrowernumber,
amountoutstanding => { '<>' => 0 },
@ -152,8 +152,9 @@ if ( $selected_accts ) {
{ order_by => 'date' }
);
$total_due = 0; # Reset and recalculate total due
map { $total_due += $_->amountoutstanding } @selected_accountlines;
$total_due = $selected_accountlines->_resultset->get_column('amountoutstanding')->sum();
@selected_accountlines = $selected_accountlines->as_list;
}