Bug 31799: (follow-up) Tidy up and fix duplicate barcode handling
Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
51d50810fa
commit
ead5f5c2f4
2 changed files with 9 additions and 21 deletions
|
@ -431,32 +431,20 @@ sub update_item {
|
|||
|
||||
$item->set_from_api($body);
|
||||
|
||||
my $barcodeSearch;
|
||||
$barcodeSearch = Koha::Items->search( { barcode => $body->{external_id} } ) if defined $body->{external_id};
|
||||
|
||||
if ( $barcodeSearch
|
||||
&& ($barcodeSearch->count > 1
|
||||
|| ($barcodeSearch->count == 1
|
||||
&& $barcodeSearch->next->itemnumber != $item->itemnumber
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => { error => "Barcode not unique" }
|
||||
);
|
||||
}
|
||||
|
||||
my $storedItem = $item->store;
|
||||
$storedItem->discard_changes;
|
||||
$item->store->discard_changes;
|
||||
|
||||
$c->render(
|
||||
status => 200,
|
||||
openapi => $storedItem->to_api
|
||||
openapi => $item->to_api
|
||||
);
|
||||
}
|
||||
catch {
|
||||
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
|
||||
return $c->render(
|
||||
status => 409,
|
||||
openapi => { error => 'Duplicate barcode.' }
|
||||
);
|
||||
}
|
||||
$c->unhandled_exception($_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1792,7 +1792,7 @@ subtest 'update_item() tests' => sub {
|
|||
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
|
||||
external_id => $other_item->barcode,
|
||||
})
|
||||
->status_is(400, 'Barcode not unique');
|
||||
->status_is(409, 'Barcode not unique');
|
||||
|
||||
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
|
||||
replacement_price => 30,
|
||||
|
|
Loading…
Reference in a new issue