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

(-)a/C4/Reserves.pm (-1 / +30 lines)
Lines 343-348 sub CanBookBeReserved{ Link Here
343
  current checkout against the high holds threshold
343
  current checkout against the high holds threshold
344
344
345
@RETURNS { status => OK },              if the Item can be reserved.
345
@RETURNS { status => OK },              if the Item can be reserved.
346
         { status => onShelfHoldsNotAllowed },  if onShelfHoldsAllowed parameter and item availability combination doesn't allow holds.
346
         { status => ageRestricted },   if the Item is age restricted for this borrower.
347
         { status => ageRestricted },   if the Item is age restricted for this borrower.
347
         { status => damaged },         if the Item is damaged.
348
         { status => damaged },         if the Item is damaged.
348
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
349
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
Lines 365-372 sub CanItemBeReserved { Link Here
365
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
366
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
366
    my $holds_per_day;        # Default to unlimited
367
    my $holds_per_day;        # Default to unlimited
367
368
369
    my $opacitemholds = 'Y';  # Itemlevel holds default to allowed
370
    my $on_shelf_holds = 0;   # Default to "if any unavailable"
371
372
    # Get calling context
373
    my $caller = (caller(1))[3];
374
368
    # we retrieve borrowers and items informations #
375
    # we retrieve borrowers and items informations #
369
    # item->{itype} will come for biblioitems if necessery
376
    # item->{itype} will come for biblioitems if necessery
377
370
    my $item       = Koha::Items->find($itemnumber);
378
    my $item       = Koha::Items->find($itemnumber);
371
    my $biblio     = $item->biblio;
379
    my $biblio     = $item->biblio;
372
    my $patron = Koha::Patrons->find( $borrowernumber );
380
    my $patron = Koha::Patrons->find( $borrowernumber );
Lines 415-420 sub CanItemBeReserved { Link Here
415
        $allowedreserves  = $rights->{reservesallowed} // $allowedreserves;
423
        $allowedreserves  = $rights->{reservesallowed} // $allowedreserves;
416
        $holds_per_record = $rights->{holds_per_record} // $holds_per_record;
424
        $holds_per_record = $rights->{holds_per_record} // $holds_per_record;
417
        $holds_per_day    = $rights->{holds_per_day};
425
        $holds_per_day    = $rights->{holds_per_day};
426
        $opacitemholds    = $rights->{opacitemholds};
427
        $on_shelf_holds   = $rights->{onshelfholds};
418
    }
428
    }
419
    else {
429
    else {
420
        $ruleitemtype = undef;
430
        $ruleitemtype = undef;
Lines 424-431 sub CanItemBeReserved { Link Here
424
        borrowernumber => $borrowernumber,
434
        borrowernumber => $borrowernumber,
425
        biblionumber   => $item->biblionumber,
435
        biblionumber   => $item->biblionumber,
426
    };
436
    };
437
427
    $search_params->{found} = undef if $params->{ignore_found_holds};
438
    $search_params->{found} = undef if $params->{ignore_found_holds};
428
439
440
    if ( $opacitemholds eq "N" and index($caller,"CanBookBeReserved") eq -1 ) {
441
        return { status => "notReservable" };
442
    }
443
444
    # Check for item on shelves and OnShelfHoldsAllowed
445
    return { status => 'onShelfHoldsNotAllowed' }
446
     if ( 0 == (
447
        $item->{'notforloan'} or
448
        $item->{'onloan'} or
449
        $item->{'itemlost'} or
450
        $item->{'withdrawn'} or
451
        $item->{'damaged'} )
452
        && ($on_shelf_holds != "1"));
453
454
    $item = Koha::Items->find( $itemnumber );
455
429
    my $holds = Koha::Holds->search($search_params);
456
    my $holds = Koha::Holds->search($search_params);
430
    if (   defined $holds_per_record && $holds_per_record ne ''
457
    if (   defined $holds_per_record && $holds_per_record ne ''
431
        && $holds->count() >= $holds_per_record ) {
458
        && $holds->count() >= $holds_per_record ) {
Lines 2264-2270 sub GetHoldRule { Link Here
2264
            itemtype     => $itemtype,
2291
            itemtype     => $itemtype,
2265
            categorycode => $categorycode,
2292
            categorycode => $categorycode,
2266
            branchcode   => $branchcode,
2293
            branchcode   => $branchcode,
2267
            rules        => ['holds_per_record', 'holds_per_day'],
2294
            rules        => ['holds_per_record', 'holds_per_day', 'opacitemholds', 'onshelfholds'],
2268
            order_by     => {
2295
            order_by     => {
2269
                -desc => [ 'categorycode', 'itemtype', 'branchcode' ]
2296
                -desc => [ 'categorycode', 'itemtype', 'branchcode' ]
2270
            }
2297
            }
Lines 2272-2277 sub GetHoldRule { Link Here
2272
    );
2299
    );
2273
    $rules->{holds_per_record} = $holds_per_x_rules->{holds_per_record};
2300
    $rules->{holds_per_record} = $holds_per_x_rules->{holds_per_record};
2274
    $rules->{holds_per_day} = $holds_per_x_rules->{holds_per_day};
2301
    $rules->{holds_per_day} = $holds_per_x_rules->{holds_per_day};
2302
    $rules->{opacitemholds} = $holds_per_x_rules->{opacitemholds};
2303
    $rules->{onshelfholds}  = $holds_per_x_rules->{onshelfholds};
2275
2304
2276
    return $rules;
2305
    return $rules;
2277
}
2306
}
(-)a/t/db_dependent/Reserves.t (-1 / +92 lines)
Lines 187-192 Koha::CirculationRules->set_rules( Link Here
187
        rules        => {
187
        rules        => {
188
            reservesallowed => 25,
188
            reservesallowed => 25,
189
            holds_per_record => 1,
189
            holds_per_record => 1,
190
            onshelfholds => 1,
190
        }
191
        }
191
    }
192
    }
192
);
193
);
Lines 986-991 subtest 'reserves.item_level_hold' => sub { Link Here
986
        $hold->delete;
987
        $hold->delete;
987
    };
988
    };
988
989
990
    subtest 'test opacitemholds rules' => sub {
991
        plan tests => 6;
992
993
        Koha::CirculationRules->set_rules(
994
            {
995
                branchcode   => undef,
996
                categorycode => undef,
997
                itemtype     => undef,
998
                rules        => {
999
                    reservesallowed => 25,
1000
                    opacitemholds => 'F',
1001
                    onshelfholds => 1,
1002
                }
1003
            }
1004
        );
1005
1006
        my $canreserve = C4::Reserves::CanBookBeReserved(
1007
            $patron->borrowernumber,
1008
            $item->biblionumber,
1009
           );
1010
1011
        is( $canreserve->{status},
1012
            'RecordHoldNotAllowed',
1013
            'record-level holds should not be possible with opacitemholds set to "Force"' );
1014
1015
        $canreserve = C4::Reserves::CanItemBeReserved(
1016
           $patron->borrowernumber,
1017
            $item->itemnumber,
1018
          );
1019
1020
        is( $canreserve->{status}, 'OK',
1021
            'item-level holds should be possible with opacitemholds set to "Force"' );
1022
1023
        Koha::CirculationRules->set_rules(
1024
            {
1025
                branchcode   => undef,
1026
                categorycode => undef,
1027
                itemtype     => undef,
1028
                rules        => {
1029
                    reservesallowed => 25,
1030
                    opacitemholds => 'N',
1031
                    onshelfholds => 1,
1032
                }
1033
            }
1034
            );
1035
1036
        $canreserve = C4::Reserves::CanBookBeReserved(
1037
            $patron->borrowernumber,
1038
            $item->biblionumber,
1039
            );
1040
1041
        is( $canreserve->{status}, 'OK',
1042
            'record-level holds should be possible with opacitemholds set to "No"' );
1043
1044
       $canreserve = C4::Reserves::CanItemBeReserved(
1045
            $patron->borrowernumber,
1046
            $item->itemnumber,
1047
            );
1048
1049
        is( $canreserve->{status}, 'notReservable',
1050
            'item-level holds should not be possible with opacitemholds set to "No"' );
1051
1052
        Koha::CirculationRules->set_rules(
1053
            {
1054
                branchcode   => undef,
1055
                categorycode => undef,
1056
                itemtype     => undef,
1057
                rules        => {
1058
                    reservesallowed => 25,
1059
                    opacitemholds => 'Y',
1060
                    onshelfholds => 1,
1061
                }
1062
            }
1063
            );
1064
1065
            $canreserve = C4::Reserves::CanBookBeReserved(
1066
            $patron->borrowernumber,
1067
            $item->biblionumber,
1068
            );
1069
1070
        is( $canreserve->{status}, 'OK',
1071
            'record-level holds should be possible with opacitemholds set to "Yes"' );
1072
1073
        $canreserve = C4::Reserves::CanItemBeReserved(
1074
            $patron->borrowernumber,
1075
            $item->itemnumber,
1076
            );
1077
1078
        is( $canreserve->{status}, 'OK',
1079
            'item-level holds should be possible with opacitemholds set to "Yes"' );
1080
    };
989
};
1081
};
990
1082
991
subtest 'MoveReserve additional test' => sub {
1083
subtest 'MoveReserve additional test' => sub {
992
- 

Return to bug 20985