Bug 23103: Cannot checkin items lost by deleted patrons with fines attached
[koha-equinox.git] / C4 / Circulation.pm
index 3061a8e..773f570 100644 (file)
@@ -2418,7 +2418,12 @@ sub _FixAccountForLostAndReturned {
     return unless $accountlines->count > 0;
     my $accountline     = $accountlines->next;
     my $total_to_refund = 0;
-    my $account = Koha::Patrons->find( $accountline->borrowernumber )->account;
+
+    return unless $accountline->borrowernumber;
+    my $patron = Koha::Patrons->find( $accountline->borrowernumber );
+    return undef unless $patron; # Patron has been deleted, nobody to credit the return to
+
+    my $account = $patron->account;
 
     # Use cases
     if ( $accountline->amount > $accountline->amountoutstanding ) {