This script uses "amount" to write off debts, when it should be using "amountoutstanding": # A 'writeoff' is a 'credit' my $writeoff = Koha::Account::Line->new( { date => \'NOW()', amount => 0 - $line->amount, <== HERE credit_type_code => 'WRITEOFF', status => 'ADDED', amountoutstanding => 0 - $line->amount, <== HERE manager_id => undef, borrowernumber => $line->borrowernumber, interface => 'intranet', branchcode => undef, } )->store(); my $writeoff_offset = Koha::Account::Offset->new( { credit_id => $writeoff->accountlines_id, type => 'WRITEOFF', amount => $line->amount <== HERE } )->store(); Patch coming.
Created attachment 127461 [details] [review] Bug 28994: Fix logical errors with amount vs amoutoutstanding The writeoff debts script contained an error whereby we could writeoff more than the current outstanding debt of a charge. This patch corrects that mistake by passing amountoutstanding in place of amount in the writeoff and offset creation lines.
Magnus is completely right here.. my mistake :(. I've just implemented the patch he suggested so I'll give him credit and then do a fast QA on it as I feel it's actually a pretty big bug that needs resolving.
Created attachment 127462 [details] [review] Bug 28994: Fix logical errors with amount vs amoutoutstanding The writeoff debts script contained an error whereby we could writeoff more than the current outstanding debt of a charge. This patch corrects that mistake by passing amountoutstanding in place of amount in the writeoff and offset creation lines. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Pushed to master for 21.11, thanks to everybody involved!
Pushed to 21.05.x for 21.05.05
Depends on Bug 27049 not in 20.11.x