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

(-)a/C4/Reserves.pm (-2 / +2 lines)
Lines 326-332 sub CanBookBeReserved{ Link Here
326
         { status => libraryNotFound },   if given branchcode is not an existing library
326
         { status => libraryNotFound },   if given branchcode is not an existing library
327
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
327
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
328
         { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode
328
         { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode
329
	 { status => alreadyReserved }, if the borrower has already reserved this item.
329
         { status => alreadyReserved }, if the borrower has already reserved this item.
330
330
331
=cut
331
=cut
332
332
Lines 408-414 sub CanItemBeReserved { Link Here
408
        $ruleitemtype = '*';
408
        $ruleitemtype = '*';
409
    }
409
    }
410
410
411
    my $holds = Koha::Holds->search(
411
    $holds = Koha::Holds->search(
412
        {
412
        {
413
            borrowernumber => $borrowernumber,
413
            borrowernumber => $borrowernumber,
414
            biblionumber   => $item->biblionumber,
414
            biblionumber   => $item->biblionumber,
(-)a/reserve/request.pl (-2 / +2 lines)
Lines 242-249 foreach my $biblionumber (@biblionumbers) { Link Here
242
            }
242
            }
243
            elsif ( grep { $canReserve->{status} eq $_ }
243
            elsif ( grep { $canReserve->{status} eq $_ }
244
                (qw(ageRestricted alreadyReserved none_available)) )
244
                (qw(ageRestricted alreadyReserved none_available)) )
245
	    {
245
            {
246
		$template->param( $canReserve->{status} => 1 );
246
                $template->param( $canReserve->{status} => 1 );
247
                $biblioloopiter{ $canReserve->{status} } = 1;
247
                $biblioloopiter{ $canReserve->{status} } = 1;
248
            }
248
            }
249
            else {
249
            else {
(-)a/t/db_dependent/Holds.t (-48 / +25 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 59;
10
use Test::More tests => 63;
11
use MARC::Record;
11
use MARC::Record;
12
12
13
use C4::Biblio;
13
use C4::Biblio;
Lines 282-308 ok( Link Here
282
    '... unless canreservefromotherbranches is ON (bug 2394)'
282
    '... unless canreservefromotherbranches is ON (bug 2394)'
283
);
283
);
284
284
285
{
285
# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
286
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
286
$biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
287
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
287
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
288
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
288
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
289
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
289
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
290
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
290
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
291
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
291
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
292
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
292
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
293
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
293
my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
294
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
294
my $hold3 = Koha::Holds->find( $reserveid3 );
295
    my $hold3 = Koha::Holds->find( $reserveid3 );
295
is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
296
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
296
ModReserve({ reserve_id => $reserveid1, rank => 'del' });
297
    ModReserve({ reserve_id => $reserveid1, rank => 'del' });
297
ModReserve({ reserve_id => $reserveid2, rank => 'del' });
298
    ModReserve({ reserve_id => $reserveid2, rank => 'del' });
298
is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
299
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
300
}
301
299
302
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
300
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
303
301
304
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
302
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
305
CancelReserve({reserve_id => $reserveid3});
303
$hold = Koha::Holds->find( $reserveid3 );
304
$hold->cancel;
306
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
305
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
307
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
306
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
308
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
307
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
Lines 336-380 AddReserve( Link Here
336
my ($bibnum2, $title2, $bibitemnum2) = create_helper_biblio('CANNOT');
335
my ($bibnum2, $title2, $bibitemnum2) = create_helper_biblio('CANNOT');
337
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum2);
336
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum2);
338
is(
337
is(
339
<<<<<<< HEAD
338
    CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves',
340
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
341
=======
342
    CanItemBeReserved( $borrowernumbers[0], $itemnumber2), 'tooManyReserves',
343
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved
344
    "cannot request item if policy that matches on item-level item type forbids it"
339
    "cannot request item if policy that matches on item-level item type forbids it"
345
);
340
);
346
ModItem({ itype => 'CAN' }, $item_bibnum2, $itemnumber2);
341
ModItem({ itype => 'CAN' }, $item_bibnum2, $itemnumber2);
347
ok(
342
ok(
348
<<<<<<< HEAD
343
    CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status} eq 'OK',
349
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
350
=======
351
    CanItemBeReserved( $borrowernumbers[0], $itemnumber2) eq 'OK',
352
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved
353
    "can request item if policy that matches on item type allows it"
344
    "can request item if policy that matches on item type allows it"
354
);
345
);
355
346
356
t::lib::Mocks::mock_preference('item-level_itypes', 0);
347
t::lib::Mocks::mock_preference('item-level_itypes', 0);
357
<<<<<<< HEAD
348
ModItem({ itype => undef }, $item_bibnum, $itemnumber2);
358
ModItem({ itype => undef }, $item_bibnum, $itemnumber);
359
ok(
360
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
361
=======
362
ModItem({ itype => undef }, $item_bibnum2, $itemnumber2);
363
is(
349
is(
364
    CanItemBeReserved( $borrowernumbers[0], $itemnumber2), 'tooManyReserves',
350
    CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status} eq 'tooManyReserves',
365
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved
366
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
351
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
367
);
352
);
368
353
369
is(CanBookBeReserved($borrowernumbers[0], $bibnum), 'OK');
354
is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'OK');
370
355
371
C4::Context->set_preference('maxreserves', 1);
356
C4::Context->set_preference('maxreserves', 1);
372
is(CanBookBeReserved($borrowernumbers[0], $biblionumber), 'tooManyReserves');
357
is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'tooManyReserves');
373
358
374
C4::Context->set_preference('maxreserves', 0);
359
C4::Context->set_preference('maxreserves', 0);
375
t::lib::Mocks::mock_preference('IndependentBranches', 1);
360
t::lib::Mocks::mock_preference('IndependentBranches', 1);
376
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0);
361
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0);
377
ok(CanBookBeReserved($borrowernumbers[0], $foreign_bibnum) eq 'none_available');
362
ok(CanBookBeReserved($borrowernumbers[0], $foreign_biblio->biblionumber)->{status} eq 'none_available');
378
363
379
# Test branch item rules
364
# Test branch item rules
380
365
Lines 443-455 is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, Link Here
443
428
444
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
429
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
445
430
446
<<<<<<< HEAD
447
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
431
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
448
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
449
=======
450
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
451
    'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
432
    'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
452
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved
453
433
454
    #results should be the same for both ReservesControlBranch settings
434
    #results should be the same for both ReservesControlBranch settings
455
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
435
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
Lines 458-464 is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, Link Here
458
#reset for further tests
438
#reset for further tests
459
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
439
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
460
440
461
<<<<<<< HEAD
462
subtest 'Test max_holds per library/patron category' => sub {
441
subtest 'Test max_holds per library/patron category' => sub {
463
    plan tests => 6;
442
    plan tests => 6;
464
443
Lines 709-715 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
709
688
710
    $schema->storage->txn_rollback;
689
    $schema->storage->txn_rollback;
711
};
690
};
712
=======
691
713
# Helper method to set up a Biblio.
692
# Helper method to set up a Biblio.
714
sub create_helper_biblio {
693
sub create_helper_biblio {
715
    my $itemtype = shift;
694
    my $itemtype = shift;
Lines 731-734 sub create_helper_biblio { Link Here
731
710
732
    return AddBiblio($bib, '');
711
    return AddBiblio($bib, '');
733
}
712
}
734
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved
735
- 

Return to bug 11999