From f15a97edcd33417ab5c70a9eb3aef3409f885f48 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 5f48cfc288..6d1edbeb4d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2222,6 +2222,8 @@ sub MarkIssueReturned { # FIXME Improve the return value and handle it from callers $schema->txn_do(sub { + my $patron = Koha::Patrons->find( $borrowernumber ); + # Update the returndate value if ( $returndate ) { $issue->returndate( $returndate )->store->discard_changes; # update and refetch @@ -2245,9 +2247,18 @@ sub MarkIssueReturned { if ( C4::Context->preference('StoreLastBorrower') ) { my $item = Koha::Items->find( $itemnumber ); - my $patron = Koha::Patrons->find( $borrowernumber ); $item->last_returned_by( $patron ); } + + # 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' }); + } + }); return $issue_id; -- 2.20.1