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

(-)a/Koha/REST/V1/Checkouts.pm (-15 / +14 lines)
Lines 314-319 sub add { Link Here
314
    };
314
    };
315
}
315
}
316
316
317
317
=head3 checkin
318
=head3 checkin
318
319
319
Check in a checked out item via item_id or barcode
320
Check in a checked out item via item_id or barcode
Lines 345-352 sub checkin { Link Here
345
        my $item;
346
        my $item;
346
        if ($item_id) {
347
        if ($item_id) {
347
            $item = Koha::Items->find($item_id);
348
            $item = Koha::Items->find($item_id);
348
        }
349
        } else {
349
        else {
350
            $item = Koha::Items->find( { barcode => $barcode } );
350
            $item = Koha::Items->find( { barcode => $barcode } );
351
        }
351
        }
352
352
Lines 368-392 sub checkin { Link Here
368
            return $c->render(
368
            return $c->render(
369
                status  => 409,
369
                status  => 409,
370
                openapi => {
370
                openapi => {
371
                    error =>
371
                    error      => 'Item id and external id belong to different items',
372
                      'Item id and external id belong to different items',
373
                    error_code => 'ITEM_ID_NOT_MATCHING_EXTERNAL_ID',
372
                    error_code => 'ITEM_ID_NOT_MATCHING_EXTERNAL_ID',
374
                }
373
                }
375
            );
374
            );
376
        }
375
        }
377
376
378
        my ( $returned, $return_messages ) =
377
        my ( $returned, $return_messages ) = C4::Circulation::AddReturn(
379
          C4::Circulation::AddReturn( $item->barcode, $library_id,
378
            $item->barcode, $library_id,
380
            $exemptfine );
379
            $exemptfine
380
        );
381
381
382
        my $response = { returned => $returned, messages => $return_messages };
382
        my $response = { returned => $returned, messages => $return_messages };
383
383
384
        if ($return_messages->{BadBarcode}){
384
        if ( $return_messages->{BadBarcode} ) {
385
          $response->{error} = 'Item not found.';
385
            $response->{error} = 'Item not found.';
386
          return $c->render(
386
            return $c->render(
387
                  status  => 409,
387
                status  => 409,
388
                  openapi => $response
388
                openapi => $response
389
              );
389
            );
390
        }
390
        }
391
391
392
        unless ($returned) {
392
        unless ($returned) {
Lines 402-409 sub checkin { Link Here
402
            openapi => $response
402
            openapi => $response
403
        );
403
        );
404
404
405
    }
405
    } catch {
406
    catch {
407
        $c->unhandled_exception($_);
406
        $c->unhandled_exception($_);
408
    };
407
    };
409
}
408
}
(-)a/t/db_dependent/api/v1/checkin.t (-30 / +20 lines)
Lines 61-78 my $patron = $builder->build_object( Link Here
61
    }
61
    }
62
);
62
);
63
my $unauth_password = 'thePassword000';
63
my $unauth_password = 'thePassword000';
64
$patron->set_password(
64
$patron->set_password( { password => $unauth_password, skip_validattion => 1 } );
65
    { password => $unauth_password, skip_validattion => 1 } );
66
my $unauth_userid = $patron->userid;
65
my $unauth_userid = $patron->userid;
67
my $patron_id     = $patron->borrowernumber;
66
my $patron_id     = $patron->borrowernumber;
68
67
69
my $item1    = $builder->build_sample_item;
68
my $item1    = $builder->build_sample_item;
70
my $item1_id = $item1->id;
69
my $item1_id = $item1->id;
71
70
72
my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
71
my $itemtype       = $builder->build( { source => 'Itemtype' } )->{itemtype};
73
my $biblio_2 = $builder->build_sample_biblio;
72
my $biblio_2       = $builder->build_sample_biblio;
74
my $item_2   = $builder->build_sample_item(
73
my $item_2         = $builder->build_sample_item( { biblionumber => $biblio_2->biblionumber, itype => $itemtype } );
75
    { biblionumber => $biblio_2->biblionumber, itype => $itemtype } );
76
my $item_2_barcode = $item_2->barcode;
74
my $item_2_barcode = $item_2->barcode;
77
my $item_2_id      = $item_2->id;
75
my $item_2_id      = $item_2->id;
78
76
Lines 146-176 my $reserve_id = C4::Reserves::AddReserve( Link Here
146
);
144
);
147
145
148
# empty checkin
146
# empty checkin
149
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json => {} )
147
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json => {} )->status_is(400);
150
  ->status_is(400);
151
148
152
# checkin on unknow item id
149
# checkin on unknown item id
153
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json =>
150
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json => { item_id => $non_existent_item_id } )->status_is(404)
154
      { item_id => $non_existent_item_id } )->status_is(404)
151
    ->json_is( { error => 'Item not found', error_code => 'ITEM_NOT_FOUND' } );
155
  ->json_is( { error => 'Item not found', error_code => 'ITEM_NOT_FOUND' } );
156
152
157
# checkin with unknow barcode
153
# checkin with unknown barcode
158
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json =>
154
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json => { external_id => $non_existent_item_barcode } )
159
      { external_id => $non_existent_item_barcode } )->status_is(404)
155
    ->status_is(404)->json_is( { error => 'Item not found', error_code => 'ITEM_NOT_FOUND' } );
160
  ->json_is( { error => 'Item not found', error_code => 'ITEM_NOT_FOUND' } );
161
156
162
# not isued
157
# not isued
163
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json =>
158
$t->post_ok(
164
      { item_id => $not_issued_item_id, library_id => $branchcode } )
159
    "//$userid:$password@/api/v1/checkin" => json => { item_id => $not_issued_item_id, library_id => $branchcode } )
165
  ->status_is(403)->json_is( '/returned' => 0 )
160
    ->status_is(403)->json_is( '/returned' => 0 )->json_has( '/messages' => { NotIssued => $not_issued_item_barcode } );
166
  ->json_has( '/messages' => { NotIssued => $not_issued_item_barcode } );
167
161
168
# checkin okay
162
# checkin okay
169
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json =>
163
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json => { item_id => $item1_id, library_id => $branchcode } )
170
      { item_id => $item1_id, library_id => $branchcode } )->status_is(201)
164
    ->status_is(201)->json_is( '/returned' => 1 )
171
  ->json_is( '/returned' => 1 )
165
    ->json_has( '/messages' => { TransferTrigger => 'ReturnToHome', WasReturned => '1' } );
172
  ->json_has(
173
    '/messages' => { TransferTrigger => 'ReturnToHome', WasReturned => '1' } );
174
166
175
#mismatch of item_id and barcode when both given
167
#mismatch of item_id and barcode when both given
176
$t->post_ok(
168
$t->post_ok(
Lines 182-192 $t->post_ok( Link Here
182
)->status_is(409);
174
)->status_is(409);
183
175
184
# reserved item
176
# reserved item
185
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json =>
177
$t->post_ok( "//$userid:$password@/api/v1/checkin" => json => { item_id => $item_2_id, library_id => $branchcode } )
186
      { item_id => $item_2_id, library_id => $branchcode } )->status_is(201)
178
    ->status_is(201)->json_is( '/returned' => 1 )->json_has(
187
  ->json_is( '/returned' => 1 )->json_has(
188
    '/messages' => { WasReturned => '1' },
179
    '/messages' => { WasReturned => '1' },
189
    '/ResFound' => { "ResFound"  => "Reserved" }
180
    '/ResFound' => { "ResFound"  => "Reserved" }
190
  );
181
    );
191
182
192
$schema->storage->txn_rollback;
183
$schema->storage->txn_rollback;
193
- 

Return to bug 24401