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

(-)a/Koha/REST/V1/Checkouts.pm (-1 / +17 lines)
Lines 219-227 sub add { Link Here
219
        if ($item_id) {
219
        if ($item_id) {
220
            $item = Koha::Items->find($item_id);
220
            $item = Koha::Items->find($item_id);
221
        }
221
        }
222
        if ($barcode) {
222
        else {
223
            $item = Koha::Items->find( { barcode => $barcode } );
223
            $item = Koha::Items->find( { barcode => $barcode } );
224
        }
224
        }
225
225
        unless ($item) {
226
        unless ($item) {
226
            return $c->render(
227
            return $c->render(
227
                status  => 409,
228
                status  => 409,
Lines 232-237 sub add { Link Here
232
            );
233
            );
233
        }
234
        }
234
235
236
        # check that item matches when barcode and item_id were given
237
        if (    $item_id
238
            and $barcode
239
            and ( $item->barcode ne $barcode or $item->id != $item_id ) )
240
        {
241
            return $c->render(
242
                status  => 409,
243
                openapi => {
244
                    error      => 'Item id and external id belong to different items',
245
                    error_code => 'ITEM_ID_NOT_MATCHING_EXTERNAL_ID',
246
                }
247
            );
248
        }
249
250
235
        my $patron = Koha::Patrons->find($patron_id);
251
        my $patron = Koha::Patrons->find($patron_id);
236
        unless ($patron) {
252
        unless ($patron) {
237
            return $c->render(
253
            return $c->render(
(-)a/t/db_dependent/api/v1/checkouts.t (-2 / +13 lines)
Lines 439-445 subtest 'get_availability' => sub { Link Here
439
439
440
subtest 'add checkout' => sub {
440
subtest 'add checkout' => sub {
441
441
442
    plan tests => 12;
442
    plan tests => 14;
443
443
444
    $schema->storage->txn_begin;
444
    $schema->storage->txn_begin;
445
    my $librarian = $builder->build_object(
445
    my $librarian = $builder->build_object(
Lines 469-474 subtest 'add checkout' => sub { Link Here
469
    my $item1_id      = $item1->id;
469
    my $item1_id      = $item1->id;
470
    my $item1_barcode = $item1->barcode;
470
    my $item1_barcode = $item1->barcode;
471
471
472
    my $item2         = $builder->build_sample_item;
473
    my $item2_id      = $item2->id;
474
    my $item2_barcode = $item2->barcode;
475
472
    my %issuingimpossible = ();
476
    my %issuingimpossible = ();
473
    my %needsconfirmation = ();
477
    my %needsconfirmation = ();
474
    my %alerts            = ();
478
    my %alerts            = ();
Lines 496-501 subtest 'add checkout' => sub { Link Here
496
        "//$userid:$password@/api/v1/checkouts" => json => { external_id => $item1_barcode, patron_id => $patron_id } )
500
        "//$userid:$password@/api/v1/checkouts" => json => { external_id => $item1_barcode, patron_id => $patron_id } )
497
        ->status_is(201);
501
        ->status_is(201);
498
502
503
    # mismatch of item_id and barcode when both given
504
    $t->post_ok(
505
        "//$userid:$password@/api/v1/checkouts" => json => {
506
            external_id => $item1_barcode,
507
            item_id     => $item2_id,
508
            patron_id   => $patron_id
509
        }
510
    )->status_is(409);
499
511
500
    # Needs confirm
512
    # Needs confirm
501
    %needsconfirmation = ( confirm1 => 1, confirm2 => 'please' );
513
    %needsconfirmation = ( confirm1 => 1, confirm2 => 'please' );
502
- 

Return to bug 37253