From a97bf5252b572e4c8777349e41c440965593743e 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 dc12cd3352..24a6ee3ad8 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2202,6 +2202,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 @@ -2225,7 +2237,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.11.0