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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 1444-1450 sub checkHighHolds { Link Here
1444
1444
1445
            # If the number of holds is less than the count of items we have
1445
            # If the number of holds is less than the count of items we have
1446
            # plus the number of holds allowed above that count, we can stop here
1446
            # plus the number of holds allowed above that count, we can stop here
1447
            if ( $holds->count() <= $threshold ) {
1447
            if ( $holds->count() < $threshold ) {
1448
                return $return_data;
1448
                return $return_data;
1449
            }
1449
            }
1450
        }
1450
        }
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-14 / +37 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 => 26;
33
use Test::More tests => 31;
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 99-104 my $item = shift(@items); Link Here
99
my $patron = shift(@patrons);
99
my $patron = shift(@patrons);
100
my $patron_hold = Koha::Holds->find({ borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber });
100
my $patron_hold = Koha::Holds->find({ borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber });
101
101
102
my $holds = Koha::Holds->search({ biblionumber => $item->biblionumber });
103
is( $holds->count, 6, "Should have 6 holds in total" );
104
102
Koha::CirculationRules->set_rules(
105
Koha::CirculationRules->set_rules(
103
    {
106
    {
104
        branchcode   => undef,
107
        branchcode   => undef,
Lines 165-173 is($duedate->min, $orig_due->min, 'New due minute is equal to original due minut Link Here
165
is($duedate->sec, 0, 'New due date second is zero.');
168
is($duedate->sec, 0, 'New due date second is zero.');
166
169
167
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' );
170
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' );
171
172
# Note in counts below, patron's own hold is not counted ("outstanding holds" is
173
# the total number of holds minus the hold for the patron we are looking at)
174
# In the tests below, we have:
175
#     threshold = holdable items count + decreaseLoanHighHoldsValue;
176
# If the number of outstanding holds is greater than or equal to the threshold,
177
# decreaseLoanHighHolds will be activated
178
179
# 10 items, 5 outstanding holds
168
$data = C4::Circulation::checkHighHolds( $item, $patron );
180
$data = C4::Circulation::checkHighHolds( $item, $patron );
169
is( $data->{exceeded}, 0, "Should not exceed threshold" );
181
is( $data->{exceeded}, 0, "Should not exceed threshold" );
170
182
is( $data->{outstanding}, 5, "Should have 5 outstanding holds" );
171
183
172
# Place 7 more holds - patrons 5,6,7,8,9,10,11
184
# Place 7 more holds - patrons 5,6,7,8,9,10,11
173
for my $i ( 5 .. 11 ) {
185
for my $i ( 5 .. 11 ) {
Lines 180-203 for my $i ( 5 .. 11 ) { Link Here
180
        }
192
        }
181
    )->store();
193
    )->store();
182
}
194
}
195
$holds = Koha::Holds->search({ biblionumber => $item->biblionumber });
196
is( $holds->count, 13, "Should have 13 holds in total" );
183
197
184
# Note in counts below, patron's own hold is not counted
198
# 12 holds, threshold is 0 over 10 holdable items = 10
199
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 0 );
200
$data = C4::Circulation::checkHighHolds( $item, $patron );
201
is( $data->{exceeded}, 1, "Should exceed decreaseLoanHighHoldsValue of 0" );
202
is( $data->{outstanding}, 12, "Should have 12 outstanding holds" );
185
203
186
# 12 holds, threshold is 1 over 10 holdable items = 11
204
# 12 holds, threshold is 1 over 10 holdable items = 11
205
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 );
187
$data = C4::Circulation::checkHighHolds( $item, $patron );
206
$data = C4::Circulation::checkHighHolds( $item, $patron );
188
is( $data->{exceeded}, 1, "Should exceed threshold of 1" );
207
is( $data->{exceeded}, 1, "Should exceed decreaseLoanHighHoldsValue of 1" );
189
is( $data->{outstanding}, 12, "Should exceed threshold of 1" );
190
208
191
# 12 holds, threshold is 2 over 10 holdable items = 12 (equal is okay)
209
# 12 holds, threshold is 2 over 10 holdable items = 12
210
# The numbers are equal, so we should still exceed the threshold and trigger decreaseLoanHighHolds
192
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 );
211
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 );
193
$data = C4::Circulation::checkHighHolds( $item, $patron );
212
$data = C4::Circulation::checkHighHolds( $item, $patron );
194
is( $data->{exceeded}, 0, "Should not exceed threshold of 2" );
213
is( $data->{exceeded}, 1, "Should exceed decreaseLoanHighHoldsValue of 2" );
214
215
# 12 holds, threshold is 3 over 10 holdable items = 13
216
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 3 );
217
$data = C4::Circulation::checkHighHolds( $item, $patron );
218
is( $data->{exceeded}, 0, "Should not exceed decreaseLoanHighHoldsValue of 3" );
195
219
196
my $unholdable = pop(@items);
220
my $unholdable = pop(@items);
197
$unholdable->damaged(-1);
221
$unholdable->damaged(-1);
198
$unholdable->store();
222
$unholdable->store();
199
223
200
# 12 holds, threshold is 2 over 9 holdable items = 11
224
# 12 holds, threshold is 3 over 9 holdable items = 12
201
$data = C4::Circulation::checkHighHolds( $item, $patron );
225
$data = C4::Circulation::checkHighHolds( $item, $patron );
202
is( $data->{exceeded}, 1, "Should exceed threshold with one damaged item" );
226
is( $data->{exceeded}, 1, "Should exceed threshold with one damaged item" );
203
227
Lines 205-211 $unholdable->damaged(0); Link Here
205
$unholdable->itemlost(-1);
229
$unholdable->itemlost(-1);
206
$unholdable->store();
230
$unholdable->store();
207
231
208
# 12 holds, threshold is 2 over 9 holdable items = 11
232
# 12 holds, threshold is 3 over 9 holdable items = 12
209
$data = C4::Circulation::checkHighHolds( $item, $patron );
233
$data = C4::Circulation::checkHighHolds( $item, $patron );
210
is( $data->{exceeded}, 1, "Should exceed threshold with one lost item" );
234
is( $data->{exceeded}, 1, "Should exceed threshold with one lost item" );
211
235
Lines 213-219 $unholdable->itemlost(0); Link Here
213
$unholdable->notforloan(-1);
237
$unholdable->notforloan(-1);
214
$unholdable->store();
238
$unholdable->store();
215
239
216
# 12 holds, threshold is 2 over 9 holdable items = 11
240
# 12 holds, threshold is 3 over 9 holdable items = 12
217
$data = C4::Circulation::checkHighHolds( $item, $patron );
241
$data = C4::Circulation::checkHighHolds( $item, $patron );
218
is( $data->{exceeded}, 1, "Should exceed threshold with one notforloan item" );
242
is( $data->{exceeded}, 1, "Should exceed threshold with one notforloan item" );
219
243
Lines 221-234 $unholdable->notforloan(0); Link Here
221
$unholdable->withdrawn(-1);
245
$unholdable->withdrawn(-1);
222
$unholdable->store();
246
$unholdable->store();
223
247
224
# 12 holds, threshold is 2 over 9 holdable items = 11
248
# 12 holds, threshold is 3 over 9 holdable items = 12
225
$data = C4::Circulation::checkHighHolds( $item, $patron );
249
$data = C4::Circulation::checkHighHolds( $item, $patron );
226
is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" );
250
is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" );
227
251
228
$patron_hold->found('F')->store;
252
$patron_hold->found('F')->store;
229
# 11 holds, threshold is 2 over 9 holdable items = 11
253
# 11 holds, threshold is 3 over 9 holdable items = 12
230
$data = C4::Circulation::checkHighHolds( $item, $patron );
254
$data = C4::Circulation::checkHighHolds( $item, $patron );
231
is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" );
255
is( $data->{exceeded}, 1, "Should exceed threshold with one found item" );
232
$patron_hold->found(undef)->store;
256
$patron_hold->found(undef)->store;
233
257
234
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
258
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
235
- 

Return to bug 34902