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

(-)a/C4/ILSDI/Services.pm (-4 / +6 lines)
Lines 667-673 sub HoldTitle { Link Here
667
    my $title = $biblio ? $biblio->title : '';
667
    my $title = $biblio ? $biblio->title : '';
668
668
669
    # Check if the biblio can be reserved
669
    # Check if the biblio can be reserved
670
    return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber )->{status} eq 'OK';
670
    my $code = CanBookBeReserved( $borrowernumber, $biblionumber )->{status};
671
    return { code => $code } unless ( $code eq 'OK' );
671
672
672
    my $branch;
673
    my $branch;
673
674
Lines 743-751 sub HoldItem { Link Here
743
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
744
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
744
745
745
    # Check for item disponibility
746
    # Check for item disponibility
746
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
747
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber )->{status};
747
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
748
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber )->{status};
748
    return { code => 'NotHoldable' } unless $canbookbereserved->{status} eq 'OK' and $canitembereserved->{status} eq 'OK';
749
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
750
    return { code => $canbookbereserved } unless $canbookbereserved eq 'OK';
749
751
750
    # Pickup branch management
752
    # Pickup branch management
751
    my $branch;
753
    my $branch;
(-)a/t/db_dependent/ILSDI_Services.t (-1 / +95 lines)
Lines 287-289 subtest 'LookupPatron test' => sub { Link Here
287
    # Cleanup
287
    # Cleanup
288
    $schema->storage->txn_rollback;
288
    $schema->storage->txn_rollback;
289
};
289
};
290
- 
290
291
292
subtest 'Holds test' => sub {
293
294
    plan tests => 3;
295
296
    $schema->storage->txn_begin;
297
298
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
299
300
    my $patron = $builder->build({
301
        source => 'Borrower',
302
    });
303
304
    my $biblio = $builder->build({
305
        source => 'Biblio',
306
    });
307
308
    my $biblioitems = $builder->build({
309
        source => 'Biblioitem',
310
        value => {
311
            biblionumber => $biblio->{biblionumber},
312
        }
313
    });
314
315
    my $item = $builder->build({
316
        source => 'Item',
317
        value => {
318
            biblionumber => $biblio->{biblionumber},
319
            damaged => 1
320
        }
321
    });
322
323
    my $query = new CGI;
324
    $query->param( 'patron_id', $patron->{borrowernumber});
325
    $query->param( 'bib_id', $biblio->{biblionumber});
326
327
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
328
    is( $reply->{code}, 'damaged', "Item damaged" );
329
330
    my $item_o = Koha::Items->find($item->{itemnumber});
331
    $item_o->damaged(0)->store;
332
333
    my $hold = $builder->build({
334
        source => 'Reserve',
335
        value => {
336
            borrowernumber => $patron->{borrowernumber},
337
            biblionumber => $biblio->{biblionumber},
338
            itemnumber => $item->{itemnumber}
339
        }
340
    });
341
342
    $reply = C4::ILSDI::Services::HoldTitle( $query );
343
    is( $reply->{code}, 'itemAlreadyOnHold', "Item already on hold" );
344
345
    my $biblio2 = $builder->build({
346
        source => 'Biblio',
347
    });
348
349
    my $biblioitems2 = $builder->build({
350
        source => 'Biblioitem',
351
        value => {
352
            biblionumber => $biblio2->{biblionumber},
353
        }
354
    });
355
356
    my $item2 = $builder->build({
357
        source => 'Item',
358
        value => {
359
            biblionumber => $biblio2->{biblionumber},
360
            damaged => 0
361
        }
362
    });
363
364
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
365
    my $issuingrule = $builder->build({
366
        source => 'Issuingrule',
367
        value => {
368
            categorycode => $patron->{categorycode},
369
            itemtype => $item2->{itype},
370
            branchcode => $patron->{branchcode},
371
            reservesallowed => 0,
372
        }
373
    });
374
375
    $query = new CGI;
376
    $query->param( 'patron_id', $patron->{borrowernumber});
377
    $query->param( 'bib_id', $biblio2->{biblionumber});
378
    $query->param( 'item_id', $item2->{itemnumber});
379
380
    $reply = C4::ILSDI::Services::HoldItem( $query );
381
    is( $reply->{code}, 'tooManyReserves', "Too many reserves" );
382
383
    $schema->storage->txn_rollback;
384
};

Return to bug 19945