From 32c1733e9d6e44e414898d63dd0341c15c774c09 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 17 Feb 2020 16:27:57 +0100 Subject: [PATCH] Bug 24413: Apply AutoRemoveOverduesRestrictions for lost items It's quite hard to know where this need to be fixed. it can be either MarkIssueReturned or LostItem, depending on the different cases we want to handle. This patch picked MarkIssueReturned, but maybe the similar code in AddReturn needs to be removed then. This patch fixes the original issue report by bug 24413, but is submitted for discussion --- C4/Circulation.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 747d660ea6..10dd550e07 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2214,6 +2214,18 @@ sub MarkIssueReturned { # FIXME Improve the return value and handle it from callers $schema->txn_do(sub { + my $patron = Koha::Patrons->find( $borrowernumber ); + + # Remove any OVERDUES related debarment if the borrower has no overdues + if ( C4::Context->preference('AutoRemoveOverduesRestrictions') + && $patron->debarred + && !$patron->has_overdues + && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } + ) { + DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); + } + + # Update the returndate value if ( $returndate ) { $issue->returndate( $returndate )->store->discard_changes; # update and refetch @@ -2237,7 +2249,6 @@ sub MarkIssueReturned { if ( C4::Context->preference('StoreLastBorrower') ) { my $item = Koha::Items->find( $itemnumber ); - my $patron = Koha::Patrons->find( $borrowernumber ); $item->last_returned_by( $patron ); } }); -- 2.20.1