]> git.koha-community.org Git - koha.git/commit
Bug 20325: C4::Accounts::purge_zero_balance_fees does not check account_offsets
authorKyle M Hall <kyle@bywatetsolutions.com>
Tue, 27 Mar 2018 19:16:16 +0000 (15:16 -0400)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 14 May 2018 14:54:03 +0000 (14:54 +0000)
commit450a8bd570c56c723d1a49aceb1ce80400506328
treed817aa082f04fdfa0759861b48fbc0fe968f8296
parent5a6e7a6ffbab8e42e706486b9e75abe782a696b8
Bug 20325: C4::Accounts::purge_zero_balance_fees does not check account_offsets

purge_zero_balance_fees is used in cleanup_database.pl to determine which fees can be cleaned up.

It uses a simple SQL query to determine which rows in accountlines need to be removed:

463     my $sth = $dbh->prepare(
464         q{
465             DELETE FROM accountlines
466             WHERE date < date_sub(curdate(), INTERVAL ? DAY)
467               AND ( amountoutstanding = 0 or amountoutstanding IS NULL );
468         }

The function comes with the following warning:

451 B<Warning:> Because fines and payments are not linked in accountlines, it is
452 possible for a fine to be deleted without the accompanying payment,
453 or vise versa. This won't affect the account balance, but might be
454 confusing to staff.

This was a reasonable solution prior to the addition of account_offsets in 17.11. The problem now is that rows in accountlines which are linked as credits in accountlines will *always* have amountoutstanding marked as 0. These are linked to debits via account_offsets. purge_zero_balance_fees will delete credits and leave rows in account_offsets which link to deleted credits.

Sites using the --fees option cleanup_database.pl which upgrade to 17.11 may have all of their credits removed without warning.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Accounts.t

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Conflicts:
t/db_dependent/Accounts.t
C4/Accounts.pm
t/db_dependent/Accounts.t