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

(-)a/C4/Reserves.pm (-8 / +14 lines)
Lines 317-323 sub CanBookBeReserved{ Link Here
317
    # Check if borrower has reached the maximum number of holds allowed
317
    # Check if borrower has reached the maximum number of holds allowed
318
    my $maxreserves = C4::Context->preference('maxreserves');
318
    my $maxreserves = C4::Context->preference('maxreserves');
319
    if ($maxreserves && $holds->count >= $maxreserves) {
319
    if ($maxreserves && $holds->count >= $maxreserves) {
320
        return { status => 'tooManyReserves' };
320
        return { status => 'tooManyReserves', limit => $maxreserves };
321
    }
321
    }
322
322
323
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
323
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
Lines 365-370 sub CanItemBeReserved { Link Here
365
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
365
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
366
    my $holds_per_day;        # Default to unlimited
366
    my $holds_per_day;        # Default to unlimited
367
367
368
    # Get calling context
369
    my $caller = (caller(1))[3];
370
368
    # we retrieve borrowers and items informations #
371
    # we retrieve borrowers and items informations #
369
    # item->{itype} will come for biblioitems if necessery
372
    # item->{itype} will come for biblioitems if necessery
370
    my $item       = Koha::Items->find($itemnumber);
373
    my $item       = Koha::Items->find($itemnumber);
Lines 386-398 sub CanItemBeReserved { Link Here
386
    return { status =>'itemAlreadyOnHold' }
389
    return { status =>'itemAlreadyOnHold' }
387
      if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
390
      if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
388
391
389
    # Check if borrower has reached the maximum number of holds allowed
390
    my $maxreserves = C4::Context->preference('maxreserves');
391
    my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } );
392
    if ($maxreserves && $holds->count >= $maxreserves) {
393
        return { status => 'tooManyReserves', limit => $maxreserves };
394
    }
395
396
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
392
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
397
393
398
    my $querycount = q{
394
    my $querycount = q{
Lines 416-421 sub CanItemBeReserved { Link Here
416
        $branchcode  = $borrower->{branchcode};
412
        $branchcode  = $borrower->{branchcode};
417
    }
413
    }
418
414
415
    # Check if borrower has reached the maximum number of holds allowed
416
    my $holds = $patron->holds;
417
    my $maxreserves = C4::Context->preference('maxreserves');
418
    if ( index($caller,"CanBookBeReserved") eq -1
419
         && $maxreserves
420
         && $holds->count >= $maxreserves) {
421
        return { status => 'tooManyReserves', limit => $maxreserves };
422
    }
423
419
    # we retrieve rights
424
    # we retrieve rights
420
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
425
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
421
        $ruleitemtype     = $rights->{itemtype};
426
        $ruleitemtype     = $rights->{itemtype};
Lines 433-438 sub CanItemBeReserved { Link Here
433
            biblionumber   => $item->biblionumber,
438
            biblionumber   => $item->biblionumber,
434
        }
439
        }
435
    );
440
    );
441
436
    if (   defined $holds_per_record && $holds_per_record ne ''
442
    if (   defined $holds_per_record && $holds_per_record ne ''
437
        && $holds->count() >= $holds_per_record ) {
443
        && $holds->count() >= $holds_per_record ) {
438
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
444
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
(-)a/t/db_dependent/Reserves.t (-4 / +4 lines)
Lines 1051-1057 subtest 'check maxreserve test' => sub { Link Here
1051
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1051
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1052
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype });
1052
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype });
1053
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype });
1053
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype });
1054
    my $patron = $builder->build_object({ class => "Koha::Patrons" });
1054
    my $patron = $builder->build_object({ class => "Koha::Patrons",
1055
					  value => { branchcode => $item_2->homebranch }});
1055
1056
1056
1057
1057
    # Place a hold on the title for both patrons
1058
    # Place a hold on the title for both patrons
Lines 1067-1074 subtest 'check maxreserve test' => sub { Link Here
1067
1068
1068
    my $borrowernumber = $patron->borrowernumber;
1069
    my $borrowernumber = $patron->borrowernumber;
1069
1070
1070
    is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden");
1071
    is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "CanBookBeReserved: Reserving more than maxreserves is forbidden");
1071
    is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden");
1072
    is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "CanItemBeReserved: Reserving more than maxreserves is forbidden");
1072
1073
1073
};
1074
};
1074
1075
1075
- 

Return to bug 11999