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

(-)a/C4/Reserves.pm (-5 / +6 lines)
Lines 1377-1392 sub IsAvailableForItemLevelRequest { Link Here
1377
        # we use the in-memory cache to avoid calling once per item when looping items on a biblio
1377
        # we use the in-memory cache to avoid calling once per item when looping items on a biblio
1378
1378
1379
        my $memory_cache = Koha::Cache::Memory::Lite->get_instance();
1379
        my $memory_cache = Koha::Cache::Memory::Lite->get_instance();
1380
        my $cache_key = sprintf "ItemsAnyAvailableAndNotRestricted:%s:%s", $patron->id, $item->biblionumber;
1380
        my $cache_key    = sprintf "ItemsAnyAvailableAndNotRestricted:%s:%s", $patron->id, $item->biblionumber;
1381
1381
1382
        my $any_available = $memory_cache->get_from_cache( $cache_key );
1382
        my $any_available = $memory_cache->get_from_cache($cache_key);
1383
        return $any_available ? 0 : 1 if defined( $any_available );
1383
        return $any_available ? 0 : 1 if defined($any_available);
1384
1384
1385
        $any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $item->biblionumber, patron => $patron });
1385
        $any_available =
1386
            ItemsAnyAvailableAndNotRestricted( { biblionumber => $item->biblionumber, patron => $patron } );
1386
        $memory_cache->set_in_cache( $cache_key, $any_available );
1387
        $memory_cache->set_in_cache( $cache_key, $any_available );
1387
        return $any_available ? 0 : 1;
1388
        return $any_available ? 0 : 1;
1388
1389
1389
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1390
    } else {  # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1390
        return $item->onloan || IsItemOnHoldAndFound( $item->itemnumber );
1391
        return $item->onloan || IsItemOnHoldAndFound( $item->itemnumber );
1391
    }
1392
    }
1392
}
1393
}
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-88 / +172 lines)
Lines 15-26 use t::lib::TestBuilder; Link Here
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
16
17
BEGIN {
17
BEGIN {
18
    use_ok('C4::Reserves', qw( ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest ));
18
    use_ok( 'C4::Reserves', qw( ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest ) );
19
}
19
}
20
20
21
my $schema = Koha::Database->schema;
21
my $schema = Koha::Database->schema;
22
$schema->storage->txn_begin;
22
$schema->storage->txn_begin;
23
my $dbh = C4::Context->dbh;
23
my $dbh   = C4::Context->dbh;
24
my $cache = Koha::Cache::Memory::Lite->get_instance();
24
my $cache = Koha::Cache::Memory::Lite->get_instance();
25
25
26
my $builder = t::lib::TestBuilder->new;
26
my $builder = t::lib::TestBuilder->new;
Lines 28-34 my $builder = t::lib::TestBuilder->new; Link Here
28
my $library1 = $builder->build( { source => 'Branch', } );
28
my $library1 = $builder->build( { source => 'Branch', } );
29
my $library2 = $builder->build( { source => 'Branch', } );
29
my $library2 = $builder->build( { source => 'Branch', } );
30
my $itemtype = $builder->build(
30
my $itemtype = $builder->build(
31
    {   source => 'Itemtype',
31
    {
32
        source => 'Itemtype',
32
        value  => { notforloan => 0 }
33
        value  => { notforloan => 0 }
33
    }
34
    }
34
)->{itemtype};
35
)->{itemtype};
Lines 36-42 my $itemtype = $builder->build( Link Here
36
t::lib::Mocks::mock_userenv( { branchcode => $library1->{branchcode} } );
37
t::lib::Mocks::mock_userenv( { branchcode => $library1->{branchcode} } );
37
38
38
my $patron1 = $builder->build_object(
39
my $patron1 = $builder->build_object(
39
    {   class => 'Koha::Patrons',
40
    {
41
        class => 'Koha::Patrons',
40
        value => {
42
        value => {
41
            branchcode => $library1->{branchcode},
43
            branchcode => $library1->{branchcode},
42
            dateexpiry => '3000-01-01',
44
            dateexpiry => '3000-01-01',
Lines 46-52 my $patron1 = $builder->build_object( Link Here
46
my $borrower1 = $patron1->unblessed;
48
my $borrower1 = $patron1->unblessed;
47
49
48
my $patron2 = $builder->build_object(
50
my $patron2 = $builder->build_object(
49
    {   class => 'Koha::Patrons',
51
    {
52
        class => 'Koha::Patrons',
50
        value => {
53
        value => {
51
            branchcode => $library1->{branchcode},
54
            branchcode => $library1->{branchcode},
52
            dateexpiry => '3000-01-01',
55
            dateexpiry => '3000-01-01',
Lines 55-61 my $patron2 = $builder->build_object( Link Here
55
);
58
);
56
59
57
my $patron3 = $builder->build_object(
60
my $patron3 = $builder->build_object(
58
    {   class => 'Koha::Patrons',
61
    {
62
        class => 'Koha::Patrons',
59
        value => {
63
        value => {
60
            branchcode => $library2->{branchcode},
64
            branchcode => $library2->{branchcode},
61
            dateexpiry => '3000-01-01',
65
            dateexpiry => '3000-01-01',
Lines 69-82 my $library_B = $library2->{branchcode}; Link Here
69
my $biblio       = $builder->build_sample_biblio( { itemtype => $itemtype } );
73
my $biblio       = $builder->build_sample_biblio( { itemtype => $itemtype } );
70
my $biblionumber = $biblio->biblionumber;
74
my $biblionumber = $biblio->biblionumber;
71
my $item1        = $builder->build_sample_item(
75
my $item1        = $builder->build_sample_item(
72
    {   biblionumber  => $biblionumber,
76
    {
77
        biblionumber  => $biblionumber,
73
        itype         => $itemtype,
78
        itype         => $itemtype,
74
        homebranch    => $library_A,
79
        homebranch    => $library_A,
75
        holdingbranch => $library_A
80
        holdingbranch => $library_A
76
    }
81
    }
77
);
82
);
78
my $item2 = $builder->build_sample_item(
83
my $item2 = $builder->build_sample_item(
79
    {   biblionumber  => $biblionumber,
84
    {
85
        biblionumber  => $biblionumber,
80
        itype         => $itemtype,
86
        itype         => $itemtype,
81
        homebranch    => $library_A,
87
        homebranch    => $library_A,
82
        holdingbranch => $library_A
88
        holdingbranch => $library_A
Lines 86-92 my $item2 = $builder->build_sample_item( Link Here
86
# Test hold_fulfillment_policy
92
# Test hold_fulfillment_policy
87
$dbh->do("DELETE FROM circulation_rules");
93
$dbh->do("DELETE FROM circulation_rules");
88
Koha::CirculationRules->set_rules(
94
Koha::CirculationRules->set_rules(
89
    {   categorycode => undef,
95
    {
96
        categorycode => undef,
90
        itemtype     => $itemtype,
97
        itemtype     => $itemtype,
91
        branchcode   => undef,
98
        branchcode   => undef,
92
        rules        => {
99
        rules        => {
Lines 148-202 AddReturn( $item1->barcode ); Link Here
148
155
149
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
156
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
150
157
151
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
158
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
152
                is( $is, 0, "Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
159
                    ;    # patron1 in library A, library A 0 items, library B 1 item
160
                is(
161
                    $is, 0,
162
                    "Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library"
163
                );
153
164
154
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
165
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
155
                is( $is, 1,
166
                is(
156
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
167
                    $is, 1,
157
                      . "One item is available at different library, not holdable = none available => the hold is allowed at item level" );
168
                    "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
169
                        . "One item is available at different library, not holdable = none available => the hold is allowed at item level"
170
                );
158
                $is = IsAvailableForItemLevelRequest( $item1, $patron2 );
171
                $is = IsAvailableForItemLevelRequest( $item1, $patron2 );
159
                is( $is, 1,
172
                is(
160
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
173
                    $is, 1,
161
                      . "One item is available at home library, holdable = one available => the hold is not allowed at item level" );
174
                    "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
175
                        . "One item is available at home library, holdable = one available => the hold is not allowed at item level"
176
                );
162
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
177
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
163
178
164
                #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
179
                #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
165
                $cache->flush();
180
                $cache->flush();
166
181
167
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
182
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
168
                is( $is, 1,
183
                    ;    # patron1 in library A, library A 0 items, library B 1 item
169
                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
184
                is(
185
                    $is, 1,
186
                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library"
187
                );
170
188
171
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
189
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
172
                is( $is, 0,
190
                is(
173
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
191
                    $is, 0,
174
                      . "One item is available at different library, holdable = one available => the hold is not allowed at item level" );
192
                    "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
193
                        . "One item is available at different library, holdable = one available => the hold is not allowed at item level"
194
                );
175
195
176
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
196
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
177
                $cache->flush();
197
                $cache->flush();
178
198
179
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
199
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
180
                is( $is, 0,
200
                    ;    # patron1 in library A, library A 0 items, library B 1 item
181
                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" );
201
                is(
202
                    $is, 0,
203
                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library"
204
                );
182
205
183
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
206
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
184
                is( $is, 1,
207
                is(
185
                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
208
                    $is, 1,
186
                      . "One item is available at different library, not holdable = none available => the hold is allowed at item level" );
209
                    "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
210
                        . "One item is available at different library, not holdable = none available => the hold is allowed at item level"
211
                );
187
212
188
                #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
213
                #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
189
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
214
                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
190
                $cache->flush();
215
                $cache->flush();
191
216
192
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
217
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
193
                is( $is, 1,
218
                    ;    # patron1 in library A, library A 0 items, library B 1 item
194
                    "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" );
219
                is(
220
                    $is, 1,
221
                    "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library"
222
                );
195
223
196
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
224
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
197
                is( $is, 0,
225
                is(
198
                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
226
                    $is, 0,
199
                      . "One item is available at different library, holdable = one available => the hold is not allowed at item level" );
227
                    "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
228
                        . "One item is available at different library, holdable = one available => the hold is not allowed at item level"
229
                );
200
            }
230
            }
201
231
202
            {
232
            {
Lines 205-228 AddReturn( $item1->barcode ); Link Here
205
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
235
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
206
                $cache->flush();
236
                $cache->flush();
207
237
208
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
238
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
209
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
239
                    ;    # patron1 in library A, library A 0 items, library B 1 item
240
                is(
241
                    $is, 1,
242
                    "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library"
243
                );
210
244
211
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
245
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
212
                is( $is, 0,
246
                is(
213
                        "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
247
                    $is, 0,
214
                      . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
248
                    "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
249
                        . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level"
250
                );
215
251
216
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
252
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
217
                $cache->flush();
253
                $cache->flush();
218
254
219
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
255
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
220
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" );
256
                    ;    # patron1 in library A, library A 0 items, library B 1 item
257
                is(
258
                    $is, 1,
259
                    "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library"
260
                );
221
261
222
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
262
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
223
                is( $is, 0,
263
                is(
224
                        "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
264
                    $is, 0,
225
                      . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
265
                    "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
266
                        . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level"
267
                );
226
            }
268
            }
227
        };
269
        };
228
270
Lines 244-266 AddReturn( $item1->barcode ); Link Here
244
286
245
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
287
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
246
288
247
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
289
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
248
                is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
290
                    ;    # patron1 in library A, library A 1 item
291
                is(
292
                    $is, 1,
293
                    "Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library"
294
                );
249
295
250
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
296
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
251
                is( $is, 0,
297
                is(
252
                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
298
                    $is, 0,
253
                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
299
                    "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
300
                        . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level"
301
                );
254
302
255
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
303
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
256
304
257
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
305
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
258
                is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
306
                    ;    # patron1 in library A, library A 1 item
307
                is(
308
                    $is, 1,
309
                    "Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library"
310
                );
259
311
260
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
312
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
261
                is( $is, 0,
313
                is(
262
                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
314
                    $is, 0,
263
                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
315
                    "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
316
                        . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level"
317
                );
264
            }
318
            }
265
319
266
            {
320
            {
Lines 268-304 AddReturn( $item1->barcode ); Link Here
268
322
269
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
323
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
270
324
271
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
325
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
272
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
326
                    ;    # patron1 in library A, library A 1 item
327
                is(
328
                    $is, 1,
329
                    "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library"
330
                );
273
331
274
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
332
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
275
                is( $is, 0,
333
                is(
276
                        "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
334
                    $is, 0,
277
                      . "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
335
                    "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
336
                        . "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level"
337
                );
278
338
279
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
339
                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
280
340
281
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
341
                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
282
                is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
342
                    ;    # patron1 in library A, library A 1 item
343
                is(
344
                    $is, 1,
345
                    "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library"
346
                );
283
347
284
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
348
                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
285
                is( $is, 0,
349
                is(
286
                        "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
350
                    $is, 0,
287
                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
351
                    "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
352
                        . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level"
353
                );
288
            }
354
            }
289
        };
355
        };
290
    };
356
    };
291
}
357
}
292
358
293
my $itemtype2 = $builder->build(
359
my $itemtype2 = $builder->build(
294
    {   source => 'Itemtype',
360
    {
361
        source => 'Itemtype',
295
        value  => { notforloan => 0 }
362
        value  => { notforloan => 0 }
296
    }
363
    }
297
)->{itemtype};
364
)->{itemtype};
298
my $item3 = $builder->build_sample_item( { itype => $itemtype2 } );
365
my $item3 = $builder->build_sample_item( { itype => $itemtype2 } );
299
366
300
my $hold = $builder->build(
367
my $hold = $builder->build(
301
    {   source => 'Reserve',
368
    {
369
        source => 'Reserve',
302
        value  => {
370
        value  => {
303
            itemnumber => $item3->itemnumber,
371
            itemnumber => $item3->itemnumber,
304
            found      => 'T'
372
            found      => 'T'
Lines 307-313 my $hold = $builder->build( Link Here
307
);
375
);
308
376
309
Koha::CirculationRules->set_rules(
377
Koha::CirculationRules->set_rules(
310
    {   categorycode => undef,
378
    {
379
        categorycode => undef,
311
        itemtype     => $itemtype2,
380
        itemtype     => $itemtype2,
312
        branchcode   => undef,
381
        branchcode   => undef,
313
        rules        => {
382
        rules        => {
Lines 317-323 Koha::CirculationRules->set_rules( Link Here
317
    }
386
    }
318
);
387
);
319
388
320
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
389
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } )
390
    ;    # patron1 in library A, library A 1 item
321
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" );
391
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" );
322
392
323
$is = IsAvailableForItemLevelRequest( $item3, $patron1 );
393
$is = IsAvailableForItemLevelRequest( $item3, $patron1 );
Lines 333-348 subtest 'Check holds availability with different item types' => sub { Link Here
333
    # is not checked out, because anyway $item2 unavailable for holds by rule
403
    # is not checked out, because anyway $item2 unavailable for holds by rule
334
    # (Bug 24683):
404
    # (Bug 24683):
335
405
336
    my $biblio2       = $builder->build_sample_biblio( { itemtype => $itemtype } );
406
    my $biblio2 = $builder->build_sample_biblio( { itemtype => $itemtype } );
337
    my $item4         = $builder->build_sample_item(
407
    my $item4   = $builder->build_sample_item(
338
        {   biblionumber  => $biblio2->biblionumber,
408
        {
409
            biblionumber  => $biblio2->biblionumber,
339
            itype         => $itemtype,
410
            itype         => $itemtype,
340
            homebranch    => $library_A,
411
            homebranch    => $library_A,
341
            holdingbranch => $library_A
412
            holdingbranch => $library_A
342
        }
413
        }
343
    );
414
    );
344
    my $item5 = $builder->build_sample_item(
415
    my $item5 = $builder->build_sample_item(
345
        {   biblionumber  => $biblio2->biblionumber,
416
        {
417
            biblionumber  => $biblio2->biblionumber,
346
            itype         => $itemtype2,
418
            itype         => $itemtype2,
347
            homebranch    => $library_A,
419
            homebranch    => $library_A,
348
            holdingbranch => $library_A
420
            holdingbranch => $library_A
Lines 352-358 subtest 'Check holds availability with different item types' => sub { Link Here
352
    # Test hold_fulfillment_policy
424
    # Test hold_fulfillment_policy
353
    $dbh->do("DELETE FROM circulation_rules");
425
    $dbh->do("DELETE FROM circulation_rules");
354
    Koha::CirculationRules->set_rules(
426
    Koha::CirculationRules->set_rules(
355
        {   categorycode => undef,
427
        {
428
            categorycode => undef,
356
            itemtype     => $itemtype,
429
            itemtype     => $itemtype,
357
            branchcode   => undef,
430
            branchcode   => undef,
358
            rules        => {
431
            rules        => {
Lines 365-371 subtest 'Check holds availability with different item types' => sub { Link Here
365
        }
438
        }
366
    );
439
    );
367
    Koha::CirculationRules->set_rules(
440
    Koha::CirculationRules->set_rules(
368
        {   categorycode => undef,
441
        {
442
            categorycode => undef,
369
            itemtype     => $itemtype2,
443
            itemtype     => $itemtype2,
370
            branchcode   => undef,
444
            branchcode   => undef,
371
            rules        => {
445
            rules        => {
Lines 379-385 subtest 'Check holds availability with different item types' => sub { Link Here
379
    );
453
    );
380
454
381
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
455
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
382
    is( $is, 1, "Items availability: 2 items, one allowed by smart rule but not checked out, another one not allowed to be held by smart rule" );
456
    is(
457
        $is, 1,
458
        "Items availability: 2 items, one allowed by smart rule but not checked out, another one not allowed to be held by smart rule"
459
    );
383
460
384
    $is = IsAvailableForItemLevelRequest( $item4, $patron1 );
461
    $is = IsAvailableForItemLevelRequest( $item4, $patron1 );
385
    is( $is, 0, "Item4 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
462
    is( $is, 0, "Item4 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
Lines 391-402 subtest 'Check holds availability with different item types' => sub { Link Here
391
    $cache->flush();
468
    $cache->flush();
392
469
393
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
470
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
394
    is( $is, 0, "Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" );
471
    is(
472
        $is, 0,
473
        "Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule"
474
    );
395
475
396
    $is = IsAvailableForItemLevelRequest( $item4, $patron1 );
476
    $is = IsAvailableForItemLevelRequest( $item4, $patron1 );
397
    is( $is, 1, "Item4 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
477
    is( $is, 1, "Item4 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
398
478
399
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
479
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
480
400
    # Note: read IsAvailableForItemLevelRequest sub description about CanItemBeReserved/CanBookBeReserved:
481
    # Note: read IsAvailableForItemLevelRequest sub description about CanItemBeReserved/CanBookBeReserved:
401
    is( $is, 1, "Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
482
    is( $is, 1, "Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
402
};
483
};
Lines 404-412 subtest 'Check holds availability with different item types' => sub { Link Here
404
subtest 'Check item checkout availability with ordered item' => sub {
485
subtest 'Check item checkout availability with ordered item' => sub {
405
    plan tests => 1;
486
    plan tests => 1;
406
487
407
    my $biblio2       = $builder->build_sample_biblio( { itemtype => $itemtype } );
488
    my $biblio2 = $builder->build_sample_biblio( { itemtype => $itemtype } );
408
    my $item1 = $builder->build_sample_item(
489
    my $item1   = $builder->build_sample_item(
409
        {   biblionumber  => $biblio2->biblionumber,
490
        {
491
            biblionumber  => $biblio2->biblionumber,
410
            itype         => $itemtype2,
492
            itype         => $itemtype2,
411
            homebranch    => $library_A,
493
            homebranch    => $library_A,
412
            holdingbranch => $library_A,
494
            holdingbranch => $library_A,
Lines 416-422 subtest 'Check item checkout availability with ordered item' => sub { Link Here
416
498
417
    $dbh->do("DELETE FROM circulation_rules");
499
    $dbh->do("DELETE FROM circulation_rules");
418
    Koha::CirculationRules->set_rules(
500
    Koha::CirculationRules->set_rules(
419
        {   categorycode => undef,
501
        {
502
            categorycode => undef,
420
            itemtype     => $itemtype2,
503
            itemtype     => $itemtype2,
421
            branchcode   => undef,
504
            branchcode   => undef,
422
            rules        => {
505
            rules        => {
Lines 437-445 subtest 'Check item checkout availability with ordered item' => sub { Link Here
437
subtest 'Check item availability for hold with ordered item' => sub {
520
subtest 'Check item availability for hold with ordered item' => sub {
438
    plan tests => 1;
521
    plan tests => 1;
439
522
440
    my $biblio2       = $builder->build_sample_biblio( { itemtype => $itemtype } );
523
    my $biblio2 = $builder->build_sample_biblio( { itemtype => $itemtype } );
441
    my $item1 = $builder->build_sample_item(
524
    my $item1   = $builder->build_sample_item(
442
        {   biblionumber  => $biblio2->biblionumber,
525
        {
526
            biblionumber  => $biblio2->biblionumber,
443
            itype         => $itemtype2,
527
            itype         => $itemtype2,
444
            homebranch    => $library_A,
528
            homebranch    => $library_A,
445
            holdingbranch => $library_A,
529
            holdingbranch => $library_A,
Lines 449-455 subtest 'Check item availability for hold with ordered item' => sub { Link Here
449
533
450
    $dbh->do("DELETE FROM circulation_rules");
534
    $dbh->do("DELETE FROM circulation_rules");
451
    Koha::CirculationRules->set_rules(
535
    Koha::CirculationRules->set_rules(
452
        {   categorycode => undef,
536
        {
537
            categorycode => undef,
453
            itemtype     => $itemtype2,
538
            itemtype     => $itemtype2,
454
            branchcode   => undef,
539
            branchcode   => undef,
455
            rules        => {
540
            rules        => {
Lines 467-480 subtest 'Check item availability for hold with ordered item' => sub { Link Here
467
    is( $is, 1, "Ordered items are available for hold" );
552
    is( $is, 1, "Ordered items are available for hold" );
468
};
553
};
469
554
470
471
# Cleanup
555
# Cleanup
472
$schema->storage->txn_rollback;
556
$schema->storage->txn_rollback;
473
557
474
sub set_holdallowed_rule {
558
sub set_holdallowed_rule {
475
    my ( $holdallowed, $branchcode ) = @_;
559
    my ( $holdallowed, $branchcode ) = @_;
476
    Koha::CirculationRules->set_rules(
560
    Koha::CirculationRules->set_rules(
477
        {   branchcode => $branchcode || undef,
561
        {
562
            branchcode => $branchcode || undef,
478
            itemtype   => undef,
563
            itemtype   => undef,
479
            rules      => {
564
            rules      => {
480
                holdallowed             => $holdallowed,
565
                holdallowed             => $holdallowed,
481
- 

Return to bug 34178