Bug 28994 - Make writeoff_debts.pl use amountoutstanding, not amount
Summary: Make writeoff_debts.pl use amountoutstanding, not amount
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low major (vote)
Assignee: Martin Renvoize
QA Contact: Testopia
URL:
Keywords:
Depends on: 27049
Blocks: 28995
  Show dependency treegraph
 
Reported: 2021-09-10 09:19 UTC by Magnus Enger
Modified: 2022-06-06 20:31 UTC (History)
5 users (show)

See Also:
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


Attachments
Bug 28994: Fix logical errors with amount vs amoutoutstanding (1.88 KB, patch)
2021-11-09 10:15 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 28994: Fix logical errors with amount vs amoutoutstanding (1.93 KB, patch)
2021-11-09 10:17 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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