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

(-)a/C4/Reserves.pm (-2 / +12 lines)
Lines 348-353 sub CanBookBeReserved{ Link Here
348
  current checkout against the high holds threshold
348
  current checkout against the high holds threshold
349
349
350
@RETURNS { status => OK },              if the Item can be reserved.
350
@RETURNS { status => OK },              if the Item can be reserved.
351
         { status => onShelfHoldsNotAllowed },  if onShelfHoldsAllowed parameter and item availability combination doesn't allow holds.
351
         { status => ageRestricted },   if the Item is age restricted for this borrower.
352
         { status => ageRestricted },   if the Item is age restricted for this borrower.
352
         { status => damaged },         if the Item is damaged.
353
         { status => damaged },         if the Item is damaged.
353
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
354
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
Lines 370-379 sub CanItemBeReserved { Link Here
370
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
371
    my $holds_per_record = 1; # Total number of holds allowed for this one given record
371
    my $holds_per_day;        # Default to unlimited
372
    my $holds_per_day;        # Default to unlimited
372
    my $opacitemholds = 'Y';  # Itemlevel holds default to allowed
373
    my $opacitemholds = 'Y';  # Itemlevel holds default to allowed
374
    my $on_shelf_holds = 0;   # Default to "if any unavailable"
373
    my $context = $params->{context} // '';
375
    my $context = $params->{context} // '';
374
376
375
    # we retrieve borrowers and items informations #
377
    # we retrieve borrowers and items informations #
376
    # item->{itype} will come for biblioitems if necessery
378
    # item->{itype} will come for biblioitems if necessery
379
377
    my $item       = Koha::Items->find($itemnumber);
380
    my $item       = Koha::Items->find($itemnumber);
378
    my $biblio     = $item->biblio;
381
    my $biblio     = $item->biblio;
379
    my $patron = Koha::Patrons->find( $borrowernumber );
382
    my $patron = Koha::Patrons->find( $borrowernumber );
Lines 424-429 sub CanItemBeReserved { Link Here
424
        $holds_per_record = $rights->{holds_per_record} // $holds_per_record;
427
        $holds_per_record = $rights->{holds_per_record} // $holds_per_record;
425
        $holds_per_day    = $rights->{holds_per_day};
428
        $holds_per_day    = $rights->{holds_per_day};
426
        $opacitemholds    = $rights->{opacitemholds};
429
        $opacitemholds    = $rights->{opacitemholds};
430
        $on_shelf_holds   = $rights->{onshelfholds};
427
    }
431
    }
428
    else {
432
    else {
429
        $ruleitemtype = undef;
433
        $ruleitemtype = undef;
Lines 433-440 sub CanItemBeReserved { Link Here
433
        borrowernumber => $borrowernumber,
437
        borrowernumber => $borrowernumber,
434
        biblionumber   => $item->biblionumber,
438
        biblionumber   => $item->biblionumber,
435
    };
439
    };
440
436
    $search_params->{found} = undef if $params->{ignore_found_holds};
441
    $search_params->{found} = undef if $params->{ignore_found_holds};
437
442
443
    # Check for item on shelves and OnShelfHoldsAllowed
444
    return { status => 'onShelfHoldsNotAllowed' }
445
    unless IsAvailableForItemLevelRequest($item, $patron, $pickup_branchcode,1);
446
438
    my $holds = Koha::Holds->search($search_params);
447
    my $holds = Koha::Holds->search($search_params);
439
448
440
    if ( $opacitemholds eq "N" && $context ne 'staff' ) {
449
    if ( $opacitemholds eq "N" && $context ne 'staff' ) {
Lines 1285-1290 checks with CanItemBeReserved or CanBookBeReserved. Link Here
1285
1294
1286
=cut
1295
=cut
1287
1296
1297
1288
sub IsAvailableForItemLevelRequest {
1298
sub IsAvailableForItemLevelRequest {
1289
    my $item                = shift;
1299
    my $item                = shift;
1290
    my $patron              = shift;
1300
    my $patron              = shift;
Lines 1326-1332 sub IsAvailableForItemLevelRequest { Link Here
1326
    if ( $on_shelf_holds == 1 ) {
1336
    if ( $on_shelf_holds == 1 ) {
1327
        return 1;
1337
        return 1;
1328
    } elsif ( $on_shelf_holds == 2 ) {
1338
    } elsif ( $on_shelf_holds == 2 ) {
1329
1330
        # if we have this param predefined from outer caller sub, we just need
1339
        # if we have this param predefined from outer caller sub, we just need
1331
        # to return it, so we saving from having loop inside other loop:
1340
        # to return it, so we saving from having loop inside other loop:
1332
        return  $items_any_available ? 0 : 1
1341
        return  $items_any_available ? 0 : 1
Lines 2284-2290 sub GetHoldRule { Link Here
2284
            itemtype     => $itemtype,
2293
            itemtype     => $itemtype,
2285
            categorycode => $categorycode,
2294
            categorycode => $categorycode,
2286
            branchcode   => $branchcode,
2295
            branchcode   => $branchcode,
2287
            rules        => ['holds_per_record', 'holds_per_day', 'opacitemholds'],
2296
            rules        => ['holds_per_record', 'holds_per_day', 'opacitemholds', 'onshelfholds'],
2288
            order_by     => {
2297
            order_by     => {
2289
                -desc => [ 'categorycode', 'itemtype', 'branchcode' ]
2298
                -desc => [ 'categorycode', 'itemtype', 'branchcode' ]
2290
            }
2299
            }
Lines 2293-2298 sub GetHoldRule { Link Here
2293
    $rules->{holds_per_record} = $holds_per_x_rules->{holds_per_record};
2302
    $rules->{holds_per_record} = $holds_per_x_rules->{holds_per_record};
2294
    $rules->{holds_per_day} = $holds_per_x_rules->{holds_per_day};
2303
    $rules->{holds_per_day} = $holds_per_x_rules->{holds_per_day};
2295
    $rules->{opacitemholds} = $holds_per_x_rules->{opacitemholds} // 'Y';
2304
    $rules->{opacitemholds} = $holds_per_x_rules->{opacitemholds} // 'Y';
2305
    $rules->{onshelfholds}  = $holds_per_x_rules->{onshelfholds} // '0';
2296
2306
2297
    return $rules;
2307
    return $rules;
2298
}
2308
}
(-)a/t/db_dependent/Reserves.t (-4 / +75 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 64;
20
use Test::More tests => 65;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
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 1058-1067 subtest 'reserves.item_level_hold' => sub { Link Here
1058
            }
1059
            }
1059
            );
1060
            );
1060
1061
1061
            $canreserve = C4::Reserves::CanBookBeReserved(
1062
        $canreserve = C4::Reserves::CanBookBeReserved(
1062
            $patron->borrowernumber,
1063
            $patron->borrowernumber,
1063
            $item->biblionumber,
1064
            $item->biblionumber,
1064
            );
1065
        );
1065
1066
1066
        is( $canreserve->{status}, 'OK',
1067
        is( $canreserve->{status}, 'OK',
1067
            'record-level holds should be possible with opacitemholds set to "Yes"' );
1068
            'record-level holds should be possible with opacitemholds set to "Yes"' );
Lines 1075-1080 subtest 'reserves.item_level_hold' => sub { Link Here
1075
            'item-level holds should be possible with opacitemholds set to "Yes"' );
1076
            'item-level holds should be possible with opacitemholds set to "Yes"' );
1076
    };
1077
    };
1077
1078
1079
1078
    subtest 'test opacitemholds rules in staff context' => sub {
1080
    subtest 'test opacitemholds rules in staff context' => sub {
1079
        plan tests => 2;
1081
        plan tests => 2;
1080
1082
Lines 1112-1117 subtest 'reserves.item_level_hold' => sub { Link Here
1112
    };
1114
    };
1113
};
1115
};
1114
1116
1117
subtest 'OnShelfHoldAllowed test' => sub {
1118
    plan tests => 3;
1119
    $dbh->do('DELETE FROM circulation_rules');
1120
    my $biblio = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
1121
1122
    # Create a helper item instance for testing
1123
    my $item = $builder->build_sample_item({ biblionumber => $biblio, library => $branch_1, itype => $itemtype });
1124
1125
    Koha::CirculationRules->set_rules(
1126
        {
1127
            branchcode   => undef,
1128
            categorycode => undef,
1129
            itemtype     => undef,
1130
            rules        => {
1131
                reservesallowed => 25,
1132
                opacitemholds => 'Y',
1133
                onshelfholds => 1,
1134
            }
1135
        }
1136
        );
1137
1138
    my $canreserve = C4::Reserves::CanItemBeReserved(
1139
        $patron->borrowernumber,
1140
        $item->itemnumber,
1141
        );
1142
1143
    is( $canreserve->{status}, 'OK',
1144
        'item-level holds should be possible with onshelfholdallowed set to "Yes"' );
1145
1146
    Koha::CirculationRules->set_rules(
1147
        {
1148
            branchcode   => undef,
1149
            categorycode => undef,
1150
            itemtype     => undef,
1151
            rules        => {
1152
                reservesallowed => 25,
1153
                opacitemholds => 'Y',
1154
                onshelfholds => '0',
1155
            }
1156
        });
1157
1158
    $canreserve = C4::Reserves::CanItemBeReserved(
1159
        $patron->borrowernumber,
1160
        $item->itemnumber,
1161
        );
1162
1163
    is( $canreserve->{status}, 'onShelfHoldsNotAllowed',
1164
        'item-level holds should not be possible with onshelfholdallowed set to "If any unavailable"' );
1165
1166
    Koha::CirculationRules->set_rules(
1167
        {
1168
            branchcode   => undef,
1169
            categorycode => undef,
1170
            itemtype     => undef,
1171
            rules        => {
1172
                reservesallowed => 25,
1173
                opacitemholds => 'Y',
1174
                onshelfholds => '2',
1175
            }
1176
        });
1177
1178
    $canreserve = C4::Reserves::CanItemBeReserved(
1179
        $patron->borrowernumber,
1180
        $item->itemnumber,
1181
        );
1182
1183
    is( $canreserve->{status}, 'onShelfHoldsNotAllowed',
1184
        'item-level holds should not be possible with onshelfholdallowed set to "If all unavailable"' );
1185
};
1186
1115
subtest 'MoveReserve additional test' => sub {
1187
subtest 'MoveReserve additional test' => sub {
1116
1188
1117
    plan tests => 4;
1189
    plan tests => 4;
1118
- 

Return to bug 20985