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

(-)a/C4/Circulation.pm (-4 / +12 lines)
Lines 1352-1358 sub checkHighHolds { Link Here
1352
        due_date    => undef,
1352
        due_date    => undef,
1353
    };
1353
    };
1354
1354
1355
    my $holds = Koha::Holds->search( { biblionumber => $item->biblionumber } );
1355
1356
    # Count holds on this record, ignoring the borrowers own holds as they would be filled by the checkout
1357
    my $holds = Koha::Holds->search({
1358
        biblionumber => $item->biblionumber,
1359
        borrowernumber => { '!=' => $patron->borrowernumber }
1360
    });
1356
1361
1357
    if ( $holds->count() ) {
1362
    if ( $holds->count() ) {
1358
        $return_data->{outstanding} = $holds->count();
1363
        $return_data->{outstanding} = $holds->count();
Lines 1367-1374 sub checkHighHolds { Link Here
1367
1372
1368
            # static means just more than a given number of holds on the record
1373
            # static means just more than a given number of holds on the record
1369
1374
1370
            # If the number of holds is less than the threshold, we can stop here
1375
            # If the number of holds is not above the threshold, we can stop here
1371
            if ( $holds->count() < $decreaseLoanHighHoldsValue ) {
1376
            if ( $holds->count() <= $decreaseLoanHighHoldsValue ) {
1372
                return $return_data;
1377
                return $return_data;
1373
            }
1378
            }
1374
        }
1379
        }
Lines 1385-1391 sub checkHighHolds { Link Here
1385
            }
1390
            }
1386
1391
1387
            # Remove any items that are not holdable for this patron
1392
            # Remove any items that are not holdable for this patron
1388
            @items = grep { CanItemBeReserved( $patron , $_, undef, { ignore_found_holds => 1 } )->{status} eq 'OK' } @items;
1393
            # We need to ignore hold counts as the borrower's own hold that will be filled by the checkout
1394
            # could prevent them from placing further holds
1395
            @items = grep { CanItemBeReserved( $patron, $_, undef, { ignore_hold_counts => 1 } )->{status} eq 'OK' } @items;
1389
1396
1390
            my $items_count = scalar @items;
1397
            my $items_count = scalar @items;
1391
1398
Lines 1537-1542 sub AddIssue { Link Here
1537
            );
1544
            );
1538
        }
1545
        }
1539
        else {
1546
        else {
1547
1540
            unless ($datedue) {
1548
            unless ($datedue) {
1541
                my $itype = $item_object->effective_itemtype;
1549
                my $itype = $item_object->effective_itemtype;
1542
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1550
                $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