Lines 171-177
sub delete {
Link Here
|
171 |
my $c = shift->openapi->valid_input or return; |
171 |
my $c = shift->openapi->valid_input or return; |
172 |
|
172 |
|
173 |
return try { |
173 |
return try { |
174 |
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') ); |
174 |
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') ); |
|
|
175 |
my $basket_count = $vendor->baskets->count; |
176 |
my $subscription_count = $vendor->subscriptions->count; |
177 |
my $invoice_count = $vendor->invoices->count; |
178 |
|
179 |
my $safe_to_delete = ( $basket_count == 0 && $subscription_count == 0 && $invoice_count == 0 ) ? 1 : 0; |
180 |
return $c->render( |
181 |
status => 409, |
182 |
openapi => { error => "Vendor cannot be deleted with existing baskets, subscriptions or invoices" } |
183 |
) unless $safe_to_delete; |
175 |
|
184 |
|
176 |
return $c->render_resource_not_found("Vendor") |
185 |
return $c->render_resource_not_found("Vendor") |
177 |
unless $vendor; |
186 |
unless $vendor; |