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

(-)a/C4/Reserves.pm (-6 / +9 lines)
Lines 347-355 sub CanBookBeReserved{ Link Here
347
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode, $params)
347
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode, $params)
348
  if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
348
  if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
349
349
350
  current params are 'ignore_found_holds' - if true holds that have been trapped are not counted
350
  current params are:
351
  'ignore_found_holds' - if true holds that have been trapped are not counted
351
  toward the patron limit, used by checkHighHolds to avoid counting the hold we will fill with the
352
  toward the patron limit, used by checkHighHolds to avoid counting the hold we will fill with the
352
  current checkout against the high holds threshold
353
  current checkout against the high holds threshold
354
  'ignore_hold_counts' - we use this routine to check if an item can fill a hold - on this case we
355
  should not check if there are too many holds as we only csre about reservability
353
356
354
@RETURNS { status => OK },              if the Item can be reserved.
357
@RETURNS { status => OK },              if the Item can be reserved.
355
         { status => ageRestricted },   if the Item is age restricted for this borrower.
358
         { status => ageRestricted },   if the Item is age restricted for this borrower.
Lines 454-460 sub CanItemBeReserved { Link Here
454
    $search_params->{found} = undef if $params->{ignore_found_holds};
457
    $search_params->{found} = undef if $params->{ignore_found_holds};
455
458
456
    my $holds = Koha::Holds->search($search_params);
459
    my $holds = Koha::Holds->search($search_params);
457
    if (   defined $holds_per_record && $holds_per_record ne ''
460
    if (!$params->{ignore_hold_counts} && defined $holds_per_record && $holds_per_record ne ''
458
        && $holds->count() >= $holds_per_record ) {
461
        && $holds->count() >= $holds_per_record ) {
459
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
462
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
460
    }
463
    }
Lines 464-470 sub CanItemBeReserved { Link Here
464
        reservedate    => dt_from_string->date
467
        reservedate    => dt_from_string->date
465
    });
468
    });
466
469
467
    if (   defined $holds_per_day && $holds_per_day ne ''
470
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne ''
468
        && $today_holds->count() >= $holds_per_day )
471
        && $today_holds->count() >= $holds_per_day )
469
    {
472
    {
470
        return { status => 'tooManyReservesToday', limit => $holds_per_day };
473
        return { status => 'tooManyReservesToday', limit => $holds_per_day };
Lines 497-504 sub CanItemBeReserved { Link Here
497
    }
500
    }
498
501
499
    # we check if it's ok or not
502
    # we check if it's ok or not
500
    if (   defined  $allowedreserves && $allowedreserves ne ''
503
    if ( defined  $allowedreserves && $allowedreserves ne ''
501
        && $reservecount >= $allowedreserves ) {
504
        && $reservecount >= $allowedreserves && (!$params->{ignore_hold_counts} || $allowedreserves == 0 ) ) {
502
        return { status => 'tooManyReserves', limit => $allowedreserves };
505
        return { status => 'tooManyReserves', limit => $allowedreserves };
503
    }
506
    }
504
507
Lines 510-516 sub CanItemBeReserved { Link Here
510
            rule_name    => 'max_holds',
513
            rule_name    => 'max_holds',
511
        }
514
        }
512
    );
515
    );
513
    if ( $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) {
516
    if (!$params->{ignore_hold_counts} && $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) {
514
        my $total_holds_count = Koha::Holds->search(
517
        my $total_holds_count = Koha::Holds->search(
515
            {
518
            {
516
                borrowernumber => $borrower->{borrowernumber}
519
                borrowernumber => $borrower->{borrowernumber}
(-)a/t/db_dependent/Holds.t (-2 / +7 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 => 68;
10
use Test::More tests => 70;
11
use MARC::Record;
11
use MARC::Record;
12
12
13
use C4::Biblio;
13
use C4::Biblio;
Lines 386-391 is( Link Here
386
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves',
386
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves',
387
    "cannot request item if policy that matches on item-level item type forbids it"
387
    "cannot request item if policy that matches on item-level item type forbids it"
388
);
388
);
389
is(
390
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber, undef, { ignore_hold_counts => 1 })->{status}, 'tooManyReserves',
391
    "cannot request item if policy that matches on item-level item type forbids it even if ignoring counts"
392
);
389
393
390
$item->itype('CAN')->store;
394
$item->itype('CAN')->store;
391
ok(
395
ok(
Lines 491-496 my $res_id = AddReserve( Link Here
491
495
492
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
496
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
493
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
497
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
498
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber, undef, { ignore_hold_counts => 1 } )->{status},
499
    'OK', 'Patron can reserve item if checking policy but not counts' );
494
500
495
    #results should be the same for both ReservesControlBranch settings
501
    #results should be the same for both ReservesControlBranch settings
496
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
502
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
497
- 

Return to bug 28078