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

(-)a/C4/Circulation.pm (-4 / +12 lines)
Lines 1354-1360 sub checkHighHolds { Link Here
1354
        due_date    => undef,
1354
        due_date    => undef,
1355
    };
1355
    };
1356
1356
1357
    my $holds = Koha::Holds->search( { biblionumber => $item->biblionumber } );
1357
1358
    # Count holds on this record, ignoring the borrowers own holds as they would be filled by the checkout
1359
    my $holds = Koha::Holds->search({
1360
        biblionumber => $item->biblionumber,
1361
        borrowernumber => { '!=' => $patron->borrowernumber }
1362
    });
1358
1363
1359
    if ( $holds->count() ) {
1364
    if ( $holds->count() ) {
1360
        $return_data->{outstanding} = $holds->count();
1365
        $return_data->{outstanding} = $holds->count();
Lines 1369-1376 sub checkHighHolds { Link Here
1369
1374
1370
            # static means just more than a given number of holds on the record
1375
            # static means just more than a given number of holds on the record
1371
1376
1372
            # If the number of holds is less than the threshold, we can stop here
1377
            # If the number of holds is not above the threshold, we can stop here
1373
            if ( $holds->count() < $decreaseLoanHighHoldsValue ) {
1378
            if ( $holds->count() <= $decreaseLoanHighHoldsValue ) {
1374
                return $return_data;
1379
                return $return_data;
1375
            }
1380
            }
1376
        }
1381
        }
Lines 1387-1393 sub checkHighHolds { Link Here
1387
            }
1392
            }
1388
1393
1389
            # Remove any items that are not holdable for this patron
1394
            # Remove any items that are not holdable for this patron
1390
            @items = grep { CanItemBeReserved( $patron , $_, undef, { ignore_found_holds => 1 } )->{status} eq 'OK' } @items;
1395
            # We need to ignore hold counts as the borrower's own hold that will be filled by the checkout
1396
            # could prevent them from placing further holds
1397
            @items = grep { CanItemBeReserved( $patron, $_, undef, { ignore_hold_counts => 1 } )->{status} eq 'OK' } @items;
1391
1398
1392
            my $items_count = scalar @items;
1399
            my $items_count = scalar @items;
1393
1400
Lines 1539-1544 sub AddIssue { Link Here
1539
            );
1546
            );
1540
        }
1547
        }
1541
        else {
1548
        else {
1549
1542
            unless ($datedue) {
1550
            unless ($datedue) {
1543
                my $itype = $item_object->effective_itemtype;
1551
                my $itype = $item_object->effective_itemtype;
1544
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1552
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-5 / +68 lines)
Lines 30-36 use Koha::CirculationRules; Link Here
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
use t::lib::Mocks;
31
use t::lib::Mocks;
32
32
33
use Test::More tests => 21;
33
use Test::More tests => 26;
34
34
35
my $dbh    = C4::Context->dbh;
35
my $dbh    = C4::Context->dbh;
36
my $schema = Koha::Database->new()->schema();
36
my $schema = Koha::Database->new()->schema();
Lines 129-138 t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged, Link Here
129
129
130
my $data = C4::Circulation::checkHighHolds( $item, $patron );
130
my $data = C4::Circulation::checkHighHolds( $item, $patron );
131
is( $data->{exceeded},        1,          "Static mode should exceed threshold" );
131
is( $data->{exceeded},        1,          "Static mode should exceed threshold" );
132
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
132
is( $data->{outstanding},     5,          "Should have 5 outstanding holds" );
133
is( $data->{duration},        0,          "Should have duration of 0 because of specific circulation rules" );
133
is( $data->{duration},        0,          "Should have duration of 0 because of specific circulation rules" );
134
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
134
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
135
135
136
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          5 );
137
$data = C4::Circulation::checkHighHolds( $item, $patron );
138
is( $data->{exceeded},        0,          "Static mode should not exceed threshold when it equals outstanding holds" );
139
is( $data->{outstanding},     5,          "Should have 5 outstanding holds" );
140
is( $data->{duration},        0,          "Should have duration of 0 because decrease not calculated" );
141
is( $data->{due_date},     undef,         "duedate undefined as not decreasing loan period" );
142
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          1 );
143
136
Koha::CirculationRules->set_rules(
144
Koha::CirculationRules->set_rules(
137
    {
145
    {
138
        branchcode   => undef,
146
        branchcode   => undef,
Lines 161-168 $data = C4::Circulation::checkHighHolds( $item, $patron ); Link Here
161
is( $data->{exceeded}, 0, "Should not exceed threshold" );
169
is( $data->{exceeded}, 0, "Should not exceed threshold" );
162
170
163
171
164
# Place 6 more holds - patrons 5,6,7,8,9,10
172
# Place 7 more holds - patrons 5,6,7,8,9,10,11
165
for my $i ( 5 .. 10 ) {
173
for my $i ( 5 .. 11 ) {
166
    my $patron = $patrons[$i];
174
    my $patron = $patrons[$i];
167
    my $hold   = Koha::Hold->new(
175
    my $hold   = Koha::Hold->new(
168
        {
176
        {
Lines 173-178 for my $i ( 5 .. 10 ) { Link Here
173
    )->store();
181
    )->store();
174
}
182
}
175
183
184
# Note in counts below, patron's own hold is not counted
185
176
# 12 holds, threshold is 1 over 10 holdable items = 11
186
# 12 holds, threshold is 1 over 10 holdable items = 11
177
$data = C4::Circulation::checkHighHolds( $item, $patron );
187
$data = C4::Circulation::checkHighHolds( $item, $patron );
178
is( $data->{exceeded}, 1, "Should exceed threshold of 1" );
188
is( $data->{exceeded}, 1, "Should exceed threshold of 1" );
Lines 242-245 Koha::CirculationRules->set_rule( Link Here
242
$data = C4::Circulation::checkHighHolds( $item, $patron );
252
$data = C4::Circulation::checkHighHolds( $item, $patron );
243
is( $data->{duration}, 2, "Circulation rules override system preferences" );
253
is( $data->{duration}, 2, "Circulation rules override system preferences" );
244
254
255
256
subtest "Test patron's own holds do not count towards HighHolds count" => sub {
257
258
    plan tests => 2;
259
260
    my $item = $builder->build_sample_item();
261
    my $item2 = $builder->build_sample_item({ biblionumber => $item->biblionumber });
262
    my $item3 = $builder->build_sample_item({ biblionumber => $item->biblionumber });
263
264
    my $patron = $builder->build_object({
265
        class => 'Koha::Patrons',
266
        value => {
267
            branchcode => $item->homebranch
268
        }
269
    });
270
    my $hold = $builder->build_object({
271
        class => 'Koha::Holds',
272
        value => {
273
            biblionumber => $item->biblionumber,
274
            borrowernumber => $patron->id,
275
            suspend => 0,
276
            found => undef
277
        }
278
    });
279
280
    Koha::CirculationRules->set_rules(
281
        {
282
            branchcode   => $item->homebranch,
283
            categorycode => undef,
284
            itemtype     => $item->itype,
285
            rules        => {
286
                issuelength     => '14',
287
                lengthunit      => 'days',
288
                reservesallowed => '99',
289
                holds_per_record => '1',
290
            }
291
        }
292
    );
293
294
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
295
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration',       1 );
296
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          1 );
297
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl',        'static' );
298
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged,itemlost,notforloan,withdrawn' );
299
300
    my $data = C4::Circulation::checkHighHolds( $item , $patron );
301
    ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if static decrease");
302
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl',        'dynamic' );
303
    # 3 items on record, patron has 1 hold
304
    $data = C4::Circulation::checkHighHolds( $item, $patron );
305
    ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if dynamic decrease");
306
307
};
308
245
$schema->storage->txn_rollback();
309
$schema->storage->txn_rollback();
246
- 

Return to bug 29102