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

(-)a/C4/ILSDI/Services.pm (-2 / +4 lines)
Lines 663-669 sub HoldTitle { Link Here
663
    my $title = $biblio ? $biblio->title : '';
663
    my $title = $biblio ? $biblio->title : '';
664
664
665
    # Check if the biblio can be reserved
665
    # Check if the biblio can be reserved
666
    return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber ) eq 'OK';
666
    my $code = CanBookBeReserved( $borrowernumber, $biblionumber );
667
    return { code => $code } unless ( $code eq 'OK' );
667
668
668
    my $branch;
669
    my $branch;
669
670
Lines 741-747 sub HoldItem { Link Here
741
    # Check for item disponibility
742
    # Check for item disponibility
742
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
743
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
743
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
744
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
744
    return { code => 'NotHoldable' } unless $canbookbereserved eq 'OK' and $canitembereserved eq 'OK';
745
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
746
    return { code => $canbookbereserved } unless $canbookbereserved eq 'OK';
745
747
746
    # Pickup branch management
748
    # Pickup branch management
747
    my $branch;
749
    my $branch;
(-)a/t/db_dependent/ILSDI_Services.t (-1 / +95 lines)
Lines 262-264 subtest 'LookupPatron test' => sub { Link Here
262
    # Cleanup
262
    # Cleanup
263
    $schema->storage->txn_rollback;
263
    $schema->storage->txn_rollback;
264
};
264
};
265
- 
265
266
267
subtest 'Holds test' => sub {
268
269
    plan tests => 3;
270
271
    $schema->storage->txn_begin;
272
273
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
274
275
    my $patron = $builder->build({
276
        source => 'Borrower',
277
    });
278
279
    my $biblio = $builder->build({
280
        source => 'Biblio',
281
    });
282
283
    my $biblioitems = $builder->build({
284
        source => 'Biblioitem',
285
        value => {
286
            biblionumber => $biblio->{biblionumber},
287
        }
288
    });
289
290
    my $item = $builder->build({
291
        source => 'Item',
292
        value => {
293
            biblionumber => $biblio->{biblionumber},
294
            damaged => 1
295
        }
296
    });
297
298
    my $query = new CGI;
299
    $query->param( 'patron_id', $patron->{borrowernumber});
300
    $query->param( 'bib_id', $biblio->{biblionumber});
301
302
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
303
    is( $reply->{code}, 'damaged', "Item damaged" );
304
305
    my $item_o = Koha::Items->find($item->{itemnumber});
306
    $item_o->damaged(0)->store;
307
308
    my $hold = $builder->build({
309
        source => 'Reserve',
310
        value => {
311
            borrowernumber => $patron->{borrowernumber},
312
            biblionumber => $biblio->{biblionumber},
313
            itemnumber => $item->{itemnumber}
314
        }
315
    });
316
317
    $reply = C4::ILSDI::Services::HoldTitle( $query );
318
    is( $reply->{code}, 'itemAlreadyOnHold', "Item already on hold" );
319
320
    my $biblio2 = $builder->build({
321
        source => 'Biblio',
322
    });
323
324
    my $biblioitems2 = $builder->build({
325
        source => 'Biblioitem',
326
        value => {
327
            biblionumber => $biblio2->{biblionumber},
328
        }
329
    });
330
331
    my $item2 = $builder->build({
332
        source => 'Item',
333
        value => {
334
            biblionumber => $biblio2->{biblionumber},
335
            damaged => 0
336
        }
337
    });
338
339
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
340
    my $issuingrule = $builder->build({
341
        source => 'Issuingrule',
342
        value => {
343
            categorycode => $patron->{categorycode},
344
            itemtype => $item2->{itype},
345
            branchcode => $patron->{branchcode},
346
            reservesallowed => 0,
347
        }
348
    });
349
350
    $query = new CGI;
351
    $query->param( 'patron_id', $patron->{borrowernumber});
352
    $query->param( 'bib_id', $biblio2->{biblionumber});
353
    $query->param( 'item_id', $item2->{itemnumber});
354
355
    $reply = C4::ILSDI::Services::HoldItem( $query );
356
    is( $reply->{code}, 'tooManyReserves', "Too many reserves" );
357
358
    $schema->storage->txn_rollback;
359
};

Return to bug 19945