Lines 330-339
sub delete {
Link Here
|
330 |
|
330 |
|
331 |
return try { |
331 |
return try { |
332 |
|
332 |
|
333 |
$patron->delete; |
333 |
if ( $patron->checkouts->count > 0 ) { |
334 |
return $c->render( |
334 |
return $c->render( |
335 |
status => 204, |
335 |
status => 409, |
336 |
openapi => q{} |
336 |
openapi => { error => 'Pending checkouts prevent deletion' } |
|
|
337 |
); |
338 |
} |
339 |
|
340 |
my $account = $patron->account; |
341 |
|
342 |
if ( $account->outstanding_debits->total_outstanding > 0 ) { |
343 |
return $c->render( |
344 |
status => 409, |
345 |
openapi => { error => 'Pending debts prevent deletion' } |
346 |
); |
347 |
} |
348 |
|
349 |
if ( $patron->guarantee_relationships->count > 0 ) { |
350 |
return $c->render( |
351 |
status => 409, |
352 |
openapi => { error => 'Patron is a guarantor and it prevents deletion' } |
353 |
); |
354 |
} |
355 |
|
356 |
$patron->_result->result_source->schema->txn_do( |
357 |
sub { |
358 |
$patron->move_to_deleted; |
359 |
$patron->delete; |
360 |
|
361 |
return $c->render( |
362 |
status => 204, |
363 |
openapi => q{} |
364 |
); |
365 |
} |
337 |
); |
366 |
); |
338 |
} catch { |
367 |
} catch { |
339 |
if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { |
368 |
if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { |