From e986c939f1d45fe86399a6519892f6a0680ceecc Mon Sep 17 00:00:00 2001 From: Shi Yao Wang Date: Thu, 7 Jul 2022 09:46:05 -0400 Subject: [PATCH] Bug 31060: Fine duplicates when returning item with accountline status marked as lost Make unpaid accountline switch from 'LOST' to 'UNRETURNED' when unsetting lost status from an item. To test: 1- System preferences: finesMode: Calculate and charge CalculateFinesOnReturn: Do WhenLostChargeReplacementFee: Don't charge MarkLostItemsAsReturned: uncheck from the items tab of the catalog module 2- Have a circulation rule with defined non-zero Fine amount and Fine charging interval. (Will have to use the patron category and item type associated to this circulation rule to test) 3- Checkout a document from the patron with backdated due date (backdated enough depending on the Fine charging interval set) 4- Run ./misc/cronjobs/fines.pl 5- There should be a Fine(Accruing) in accounting tab of the patron 6- Go to the checked out item detail and set Lost status: Long overdue (Lost) and click Set status 7- Now, Fine(Accruing) changed to Fine(Lost) in the accounting tab of the patron 8- In item detail, set Lost status: Choose and click Set status 9- Notice Fine(Lost) did not switch back to Fine(Accruing) in the accounting tab 10- Check in the item 11- Notice there is a duplicate fee Fine(Returned) and Fine(Lost) is still there 12- Apply the patch 13- Write off all fines of the patron 14- Repeat step 3 to 10 and notice step 9 is not true anymore 15- Notice there is only Fine(Returned) and no duplicate --- C4/Circulation.pm | 19 +++++++++++++++++++ catalogue/updateitem.pl | 10 ++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index a10503385f..6378c64aa1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -77,6 +77,7 @@ BEGIN { # FIXME subs that should probably be elsewhere push @EXPORT_OK, qw( barcodedecode + FoundItem LostItem ReturnLostItem GetPendingOnSiteCheckouts @@ -4011,6 +4012,24 @@ sub LostItem{ } } +sub FoundItem { + my $itemnumber = shift; + + my $accountlines = Koha::Account::Lines->search( + { + itemnumber => $itemnumber, + debit_type_code => 'OVERDUE', + status => 'LOST', + amountoutstanding => { '!=', 0 } + } + ); + return unless $accountlines->count; + + my $accountline = $accountlines->next; + $accountline->status('UNRETURNED'); + $accountline->store; +} + sub GetOfflineOperations { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp"); diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index 6d9022ff87..c2a3174376 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -22,7 +22,7 @@ use CGI qw ( -utf8 ); use C4::Auth qw( checkauth ); use C4::Context; use C4::Output; -use C4::Circulation qw( LostItem ); +use C4::Circulation qw( LostItem FoundItem ); use C4::Reserves; my $cgi= CGI->new; @@ -85,6 +85,12 @@ elsif ( $op eq "set_public_note" ) { # i.e., itemnotes parameter passed from for $item->store; -LostItem($itemnumber, 'moredetail') if $op eq "set_lost"; +if ($op eq "set_lost") { + if ($itemlost) { + LostItem($itemnumber, 'moredetail'); + } else { + FoundItem($itemnumber); + } +} print $cgi->redirect("moredetail.pl?" . $messages . "biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber"); -- 2.25.1