View | Details | Raw Unified | Return to bug 31799
Collapse All | Expand All

(-)a/Koha/REST/V1/Biblios.pm (-20 / +8 lines)
Lines 432-463 sub update_item { Link Here
432
432
433
        $item->set_from_api($body);
433
        $item->set_from_api($body);
434
434
435
        my $barcodeSearch;
435
        $item->store->discard_changes;
436
        $barcodeSearch = Koha::Items->search( { barcode => $body->{external_id} } ) if defined $body->{external_id};
437
438
        if ( $barcodeSearch
439
            && ($barcodeSearch->count > 1
440
                || ($barcodeSearch->count == 1
441
                    && $barcodeSearch->next->itemnumber != $item->itemnumber
442
                )
443
            )
444
        )
445
        {
446
            return $c->render(
447
                status  => 400,
448
                openapi => { error => "Barcode not unique" }
449
            );
450
        }
451
452
        my $storedItem = $item->store;
453
        $storedItem->discard_changes;
454
436
455
        $c->render(
437
        $c->render(
456
            status => 200,
438
            status => 200,
457
            openapi => $storedItem->to_api
439
            openapi => $item->to_api
458
        );
440
        );
459
    }
441
    }
460
    catch {
442
    catch {
443
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
444
            return $c->render(
445
                status  => 409,
446
                openapi => { error => 'Duplicate barcode.' }
447
            );
448
        }
461
        $c->unhandled_exception($_);
449
        $c->unhandled_exception($_);
462
    }
450
    }
463
}
451
}
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +1 lines)
Lines 1772-1778 subtest 'update_item() tests' => sub { Link Here
1772
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
1772
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
1773
      external_id => $other_item->barcode,
1773
      external_id => $other_item->barcode,
1774
    })
1774
    })
1775
    ->status_is(400, 'Barcode not unique');
1775
    ->status_is(409, 'Barcode not unique');
1776
1776
1777
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
1777
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
1778
      replacement_price => 30,
1778
      replacement_price => 30,
1779
- 

Return to bug 31799