diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c91d05643a..30e20c5806 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2176,6 +2176,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 @@ -2199,9 +2201,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;