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

(-)a/C4/Circulation.pm (-2 / +10 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 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 / +60 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 => 22;
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-135 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
Lines 161-168 $data = C4::Circulation::checkHighHolds( $item, $patron ); Link Here
161
is( $data->{exceeded}, 0, "Should not exceed threshold" );
161
is( $data->{exceeded}, 0, "Should not exceed threshold" );
162
162
163
163
164
# Place 6 more holds - patrons 5,6,7,8,9,10
164
# Place 7 more holds - patrons 5,6,7,8,9,10,11
165
for my $i ( 5 .. 10 ) {
165
for my $i ( 5 .. 11 ) {
166
    my $patron = $patrons[$i];
166
    my $patron = $patrons[$i];
167
    my $hold   = Koha::Hold->new(
167
    my $hold   = Koha::Hold->new(
168
        {
168
        {
Lines 173-178 for my $i ( 5 .. 10 ) { Link Here
173
    )->store();
173
    )->store();
174
}
174
}
175
175
176
# Note in counts below, patron's own hold is not counted
177
176
# 12 holds, threshold is 1 over 10 holdable items = 11
178
# 12 holds, threshold is 1 over 10 holdable items = 11
177
$data = C4::Circulation::checkHighHolds( $item, $patron );
179
$data = C4::Circulation::checkHighHolds( $item, $patron );
178
is( $data->{exceeded}, 1, "Should exceed threshold of 1" );
180
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 );
244
$data = C4::Circulation::checkHighHolds( $item, $patron );
243
is( $data->{duration}, 2, "Circulation rules override system preferences" );
245
is( $data->{duration}, 2, "Circulation rules override system preferences" );
244
246
247
248
subtest "Test patron's own holds do not count towards HighHolds count" => sub {
249
250
    plan tests => 2;
251
252
    my $item = $builder->build_sample_item();
253
    my $item2 = $builder->build_sample_item({ biblionumber => $item->biblionumber });
254
    my $item3 = $builder->build_sample_item({ biblionumber => $item->biblionumber });
255
256
    my $patron = $builder->build_object({
257
        class => 'Koha::Patrons',
258
        value => {
259
            branchcode => $item->homebranch
260
        }
261
    });
262
    my $hold = $builder->build_object({
263
        class => 'Koha::Holds',
264
        value => {
265
            biblionumber => $item->biblionumber,
266
            borrowernumber => $patron->id,
267
            suspend => 0,
268
            found => undef
269
        }
270
    });
271
272
    Koha::CirculationRules->set_rules(
273
        {
274
            branchcode   => $item->homebranch,
275
            categorycode => undef,
276
            itemtype     => $item->itype,
277
            rules        => {
278
                issuelength     => '14',
279
                lengthunit      => 'days',
280
                reservesallowed => '99',
281
                holds_per_record => '1',
282
            }
283
        }
284
    );
285
286
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
287
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration',       1 );
288
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          1 );
289
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl',        'static' );
290
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged,itemlost,notforloan,withdrawn' );
291
292
    my $data = C4::Circulation::checkHighHolds( $item , $patron );
293
    ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if static decrease");
294
    t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl',        'dynamic' );
295
    # 3 items on record, patron has 1 hold
296
    $data = C4::Circulation::checkHighHolds( $item, $patron );
297
    ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if dynamic decrease");
298
299
};
300
245
$schema->storage->txn_rollback();
301
$schema->storage->txn_rollback();
246
- 

Return to bug 29102