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

(-)a/C4/Reserves.pm (-19 / +14 lines)
Lines 324-330 sub CanBookBeReserved{ Link Here
324
    # Check if borrower has reached the maximum number of holds allowed
324
    # Check if borrower has reached the maximum number of holds allowed
325
    my $maxreserves = C4::Context->preference('maxreserves');
325
    my $maxreserves = C4::Context->preference('maxreserves');
326
    if ($maxreserves && $holds->count >= $maxreserves) {
326
    if ($maxreserves && $holds->count >= $maxreserves) {
327
        return { status => 'tooManyReserves' };
327
        return { status => 'tooManyReserves', limit => $maxreserves };
328
    }
328
    }
329
329
330
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
330
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
Lines 376-381 sub CanItemBeReserved { Link Here
376
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
376
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
377
    my $holds_per_day;        # Default to unlimited
377
    my $holds_per_day;        # Default to unlimited
378
378
379
    # Get calling context
380
    my $caller = (caller(1))[3];
381
379
    # we retrieve borrowers and items informations #
382
    # we retrieve borrowers and items informations #
380
    # item->{itype} will come for biblioitems if necessery
383
    # item->{itype} will come for biblioitems if necessery
381
    my $item       = Koha::Items->find($itemnumber);
384
    my $item       = Koha::Items->find($itemnumber);
Lines 397-409 sub CanItemBeReserved { Link Here
397
    return { status =>'itemAlreadyOnHold' }
400
    return { status =>'itemAlreadyOnHold' }
398
      if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
401
      if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
399
402
400
    # Check if borrower has reached the maximum number of holds allowed
401
    my $maxreserves = C4::Context->preference('maxreserves');
402
    my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } );
403
    if ($maxreserves && $holds->count >= $maxreserves) {
404
        return { status => 'tooManyReserves', limit => $maxreserves };
405
    }
406
407
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
403
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
408
404
409
    my $querycount = q{
405
    my $querycount = q{
Lines 427-432 sub CanItemBeReserved { Link Here
427
        $branchcode  = $borrower->{branchcode};
423
        $branchcode  = $borrower->{branchcode};
428
    }
424
    }
429
425
426
    # Check if borrower has reached the maximum number of holds allowed
427
    my $holds = $patron->holds;
428
    my $maxreserves = C4::Context->preference('maxreserves');
429
    if ( index($caller,"CanBookBeReserved") eq -1
430
         && $maxreserves
431
         && $holds->count >= $maxreserves) {
432
        return { status => 'tooManyReserves', limit => $maxreserves };
433
    }
434
430
    # we retrieve rights
435
    # we retrieve rights
431
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
436
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
432
        $ruleitemtype     = $rights->{itemtype};
437
        $ruleitemtype     = $rights->{itemtype};
Lines 438-462 sub CanItemBeReserved { Link Here
438
        $ruleitemtype = undef;
443
        $ruleitemtype = undef;
439
    }
444
    }
440
445
441
<<<<<<< HEAD
442
    my $search_params = {
446
    my $search_params = {
443
        borrowernumber => $borrowernumber,
447
        borrowernumber => $borrowernumber,
444
        biblionumber   => $item->biblionumber,
448
        biblionumber   => $item->biblionumber,
445
    };
449
    };
446
    $search_params->{found} = undef if $params->{ignore_found_holds};
450
    $search_params->{found} = undef if $params->{ignore_found_holds};
447
451
448
    my $holds = Koha::Holds->search($search_params);
452
    $holds = Koha::Holds->search($search_params);
449
    if (   defined $holds_per_record && $holds_per_record ne ''
453
    if (   defined $holds_per_record && $holds_per_record ne ''
450
        && $holds->count() >= $holds_per_record ) {
454
        && $holds->count() >= $holds_per_record ) {
451
=======
452
    $holds = Koha::Holds->search(
453
        {
454
            borrowernumber => $borrowernumber,
455
            biblionumber   => $item->biblionumber,
456
        }
457
    );
458
    if ( $holds->count() >= $holds_per_record ) {
459
>>>>>>> Bug 11999: Add maxreserves check in CanBookBeReserved and CanItemBeReserved
460
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
455
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
461
    }
456
    }
462
457
(-)a/t/db_dependent/Reserves.t (-9 / +6 lines)
Lines 17-27 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
<<<<<<< HEAD
20
use Test::More tests => 65;
21
use Test::More tests => 64;
22
=======
23
use Test::More tests => 63;
24
>>>>>>> Bug 11999: Test improvements + check maxreserves
25
use Test::MockModule;
21
use Test::MockModule;
26
use Test::Warn;
22
use Test::Warn;
27
23
Lines 1171-1177 subtest 'check maxreserve test' => sub { Link Here
1171
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1167
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1172
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype });
1168
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype });
1173
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype });
1169
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype });
1174
    my $patron = $builder->build_object({ class => "Koha::Patrons" });
1170
    my $patron = $builder->build_object({ class => "Koha::Patrons",
1171
                                          value => { branchcode => $item_2->homebranch }});
1175
1172
1176
1173
1177
    # Place a hold on the title for both patrons
1174
    # Place a hold on the title for both patrons
Lines 1187-1194 subtest 'check maxreserve test' => sub { Link Here
1187
1184
1188
    my $borrowernumber = $patron->borrowernumber;
1185
    my $borrowernumber = $patron->borrowernumber;
1189
1186
1190
    is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden");
1187
    is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "CanBookBeReserved: Reserving more than maxreserves is forbidden");
1191
    is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden");
1188
    is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "CanItemBeReserved: Reserving more than maxreserves is forbidden");
1189
1192
};
1190
};
1193
1191
1194
sub count_hold_print_messages {
1192
sub count_hold_print_messages {
1195
- 

Return to bug 11999