Bug 28994

Summary: Make writeoff_debts.pl use amountoutstanding, not amount
Product: Koha Reporter: Magnus Enger <magnus>
Component: Command-line UtilitiesAssignee: Martin Renvoize <martin.renvoize>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: major    
Priority: P5 - low CC: fridolin.somers, jonathan.druart, kyle, martin.renvoize, robin
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.11.00,21.05.05
Bug Depends on: 27049    
Bug Blocks: 28995    
Attachments: Bug 28994: Fix logical errors with amount vs amoutoutstanding
Bug 28994: Fix logical errors with amount vs amoutoutstanding

Description Magnus Enger 2021-09-10 09:19:45 UTC
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.
Comment 1 Martin Renvoize 2021-11-09 10:15:01 UTC
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.
Comment 2 Martin Renvoize 2021-11-09 10:16:28 UTC
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.
Comment 3 Martin Renvoize 2021-11-09 10:17:37 UTC
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>
Comment 4 Jonathan Druart 2021-11-15 11:39:32 UTC
Pushed to master for 21.11, thanks to everybody involved!
Comment 5 Kyle M Hall 2021-11-19 15:48:05 UTC
Pushed to 21.05.x for 21.05.05
Comment 6 Fridolin Somers 2021-11-19 20:49:10 UTC
Depends on Bug 27049 not in 20.11.x