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