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

(-)a/Koha/REST/V1/Biblios.pm (-20 / +8 lines)
Lines 366-397 sub update_item { Link Here
366
366
367
        $item->set_from_api($body);
367
        $item->set_from_api($body);
368
368
369
        my $barcodeSearch;
369
        $item->store->discard_changes;
370
        $barcodeSearch = Koha::Items->search( { barcode => $body->{external_id} } ) if defined $body->{external_id};
371
372
        if ( $barcodeSearch
373
            && ($barcodeSearch->count > 1
374
                || ($barcodeSearch->count == 1
375
                    && $barcodeSearch->next->itemnumber != $item->itemnumber
376
                )
377
            )
378
        )
379
        {
380
            return $c->render(
381
                status  => 400,
382
                openapi => { error => "Barcode not unique" }
383
            );
384
        }
385
386
        my $storedItem = $item->store;
387
        $storedItem->discard_changes;
388
370
389
        $c->render(
371
        $c->render(
390
            status => 200,
372
            status => 200,
391
            openapi => $storedItem->to_api
373
            openapi => $item->to_api
392
        );
374
        );
393
    }
375
    }
394
    catch {
376
    catch {
377
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
378
            return $c->render(
379
                status  => 409,
380
                openapi => { error => 'Duplicate barcode.' }
381
            );
382
        }
395
        $c->unhandled_exception($_);
383
        $c->unhandled_exception($_);
396
    }
384
    }
397
}
385
}
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +1 lines)
Lines 817-823 subtest 'update_item() tests' => sub { Link Here
817
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
817
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
818
      external_id => $other_item->barcode,
818
      external_id => $other_item->barcode,
819
    })
819
    })
820
    ->status_is(400, 'Barcode not unique');
820
    ->status_is(409, 'Barcode not unique');
821
821
822
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
822
  $t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => {
823
      replacement_price => 30,
823
      replacement_price => 30,
824
- 

Return to bug 31799