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

(-)a/C4/Reserves.pm (-15 / +7 lines)
Lines 330-336 sub CanBookBeReserved{ Link Here
330
    # Check if borrower has reached the maximum number of holds allowed
330
    # Check if borrower has reached the maximum number of holds allowed
331
    my $maxreserves = C4::Context->preference('maxreserves');
331
    my $maxreserves = C4::Context->preference('maxreserves');
332
    if ($maxreserves && $holds->count >= $maxreserves) {
332
    if ($maxreserves && $holds->count >= $maxreserves) {
333
        return { status => 'tooManyReserves' };
333
        return { status => 'tooManyReserves', limit => $maxreserves };
334
    }
334
    }
335
335
336
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
336
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
Lines 382-387 sub CanItemBeReserved { Link Here
382
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
382
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
383
    my $holds_per_day;        # Default to unlimited
383
    my $holds_per_day;        # Default to unlimited
384
384
385
    # Get calling context
386
    my $caller = (caller(1))[3];
387
385
    # we retrieve borrowers and items informations #
388
    # we retrieve borrowers and items informations #
386
    # item->{itype} will come for biblioitems if necessery
389
    # item->{itype} will come for biblioitems if necessery
387
    my $item       = Koha::Items->find($itemnumber);
390
    my $item       = Koha::Items->find($itemnumber);
Lines 403-420 sub CanItemBeReserved { Link Here
403
    return { status =>'itemAlreadyOnHold' }
406
    return { status =>'itemAlreadyOnHold' }
404
      if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
407
      if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
405
408
406
<<<<<<< HEAD
407
    # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set)
409
    # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set)
408
    if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
410
    if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
409
        && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) {
411
        && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) {
410
        return { status =>'alreadypossession' };
412
        return { status =>'alreadypossession' };
411
=======
413
    }
414
412
    # Check if borrower has reached the maximum number of holds allowed
415
    # Check if borrower has reached the maximum number of holds allowed
413
    my $maxreserves = C4::Context->preference('maxreserves');
416
    my $maxreserves = C4::Context->preference('maxreserves');
414
    my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } );
417
    my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } );
415
    if ($maxreserves && $holds->count >= $maxreserves) {
418
    if ($maxreserves && $holds->count >= $maxreserves) {
416
        return { status => 'tooManyReserves', limit => $maxreserves };
419
        return { status => 'tooManyReserves', limit => $maxreserves };
417
>>>>>>> Bug 11999: Add maxreserves check in CanBookBeReserved and CanItemBeReserved
418
    }
420
    }
419
421
420
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
422
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
Lines 451-475 sub CanItemBeReserved { Link Here
451
        $ruleitemtype = undef;
453
        $ruleitemtype = undef;
452
    }
454
    }
453
455
454
<<<<<<< HEAD
455
    my $search_params = {
456
    my $search_params = {
456
        borrowernumber => $borrowernumber,
457
        borrowernumber => $borrowernumber,
457
        biblionumber   => $item->biblionumber,
458
        biblionumber   => $item->biblionumber,
458
    };
459
    };
459
    $search_params->{found} = undef if $params->{ignore_found_holds};
460
    $search_params->{found} = undef if $params->{ignore_found_holds};
460
461
461
    my $holds = Koha::Holds->search($search_params);
462
    $holds = Koha::Holds->search($search_params);
462
    if (   defined $holds_per_record && $holds_per_record ne ''
463
    if (   defined $holds_per_record && $holds_per_record ne ''
463
        && $holds->count() >= $holds_per_record ) {
464
        && $holds->count() >= $holds_per_record ) {
464
=======
465
    $holds = Koha::Holds->search(
466
        {
467
            borrowernumber => $borrowernumber,
468
            biblionumber   => $item->biblionumber,
469
        }
470
    );
471
    if ( $holds->count() >= $holds_per_record ) {
472
>>>>>>> Bug 11999: Add maxreserves check in CanBookBeReserved and CanItemBeReserved
473
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
465
        return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
474
    }
466
    }
475
467
(-)a/t/db_dependent/Reserves.t (-8 / +8 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 65;
20
use Test::More tests => 66;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 1156-1162 subtest 'CheckReserves additional test' => sub { Link Here
1156
    is( scalar @$possible_reserves, 2, 'We do get both reserves' );
1156
    is( scalar @$possible_reserves, 2, 'We do get both reserves' );
1157
};
1157
};
1158
1158
1159
<<<<<<< HEAD
1160
subtest 'AllowHoldOnPatronPossession test' => sub {
1159
subtest 'AllowHoldOnPatronPossession test' => sub {
1161
1160
1162
    plan tests => 4;
1161
    plan tests => 4;
Lines 1193-1199 subtest 'AllowHoldOnPatronPossession test' => sub { Link Here
1193
                                       $item->itemnumber)->{status},
1192
                                       $item->itemnumber)->{status},
1194
       'OK',
1193
       'OK',
1195
       'Patron can place hold on an item loaned to itself');
1194
       'Patron can place hold on an item loaned to itself');
1196
=======
1195
};
1196
1197
subtest 'check maxreserve test' => sub {
1197
subtest 'check maxreserve test' => sub {
1198
1198
1199
    plan tests => 2;
1199
    plan tests => 2;
Lines 1205-1211 subtest 'check maxreserve test' => sub { Link Here
1205
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1205
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1206
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype });
1206
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype });
1207
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype });
1207
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype });
1208
    my $patron = $builder->build_object({ class => "Koha::Patrons" });
1208
    my $patron = $builder->build_object({ class => "Koha::Patrons",
1209
                                          value => { branchcode => $item_2->homebranch }});
1209
1210
1210
1211
1211
    # Place a hold on the title for both patrons
1212
    # Place a hold on the title for both patrons
Lines 1221-1229 subtest 'check maxreserve test' => sub { Link Here
1221
1222
1222
    my $borrowernumber = $patron->borrowernumber;
1223
    my $borrowernumber = $patron->borrowernumber;
1223
1224
1224
    is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden");
1225
    is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "CanBookBeReserved: Reserving more than maxreserves is forbidden");
1225
    is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden");
1226
    is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "CanItemBeReserved: Reserving more than maxreserves is forbidden");
1226
>>>>>>> Bug 11999: Test improvements + check maxreserves
1227
1227
};
1228
};
1228
1229
1229
sub count_hold_print_messages {
1230
sub count_hold_print_messages {
1230
- 

Return to bug 11999