From 754e900fbec98503589770a73ac4164d32b732df Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 13 May 2020 14:11:38 +0100 Subject: [PATCH] Bug 8338: Remove zero amount overdues on backdated returns where appropriate This patch removes any overdues which would be reversed on a backdated return if CalcFineOnBackdate is enabled and the user has not already attempted to pay off the accruing fine. Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit 3f3534a8eeed87869fd6a858866455c10087d7e1) Signed-off-by: Lucas Gass --- C4/Circulation.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 733c0f17e9..f0bfcff1c3 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2433,9 +2433,12 @@ sub _FixOverduesOnReturn { return 0 unless $accountlines->count; # no warning, there's just nothing to fix my $accountline = $accountlines->next; + my $payments = $accountline->credits; my $amountoutstanding = $accountline->amountoutstanding; - if ($exemptfine && ($amountoutstanding != 0)) { + if ( $accountline->amount == 0 && $payments->count == 0 ) { + $accountline->delete; + } elsif ($exemptfine && ($amountoutstanding != 0)) { my $account = Koha::Account->new({patron_id => $borrowernumber}); my $credit = $account->add_credit( { @@ -2451,15 +2454,15 @@ sub _FixOverduesOnReturn { $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); $accountline->status('FORGIVEN'); + $accountline->store(); if (C4::Context->preference("FinesLog")) { &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); } } else { $accountline->status($status); + $accountline->store(); } - - return $accountline->store(); } ); -- 2.39.5