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

(-)a/Koha/Biblio.pm (-1 / +1 lines)
Lines 174-180 sub can_be_transferred { Link Here
174
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
174
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
175
175
176
Returns possible pickup locations for this biblio items, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
176
Returns possible pickup locations for this biblio items, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
177
and if item can be transfered to each pickup location.
177
and if item can be transferred to each pickup location.
178
178
179
=cut
179
=cut
180
180
(-)a/Koha/Item.pm (-2 / +4 lines)
Lines 27-32 use Koha::DateUtils qw( dt_from_string ); Link Here
27
27
28
use C4::Context;
28
use C4::Context;
29
use C4::Circulation;
29
use C4::Circulation;
30
use C4::Reserves;
30
use Koha::Checkouts;
31
use Koha::Checkouts;
31
use Koha::IssuingRules;
32
use Koha::IssuingRules;
32
use Koha::Item::Transfer::Limits;
33
use Koha::Item::Transfer::Limits;
Lines 300-306 sub can_be_transferred { Link Here
300
@pickup_locations = $item->pickup_locations( {patron => $patron } )
301
@pickup_locations = $item->pickup_locations( {patron => $patron } )
301
302
302
Returns possible pickup locations for this item, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
303
Returns possible pickup locations for this item, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
303
and if item can be transfered to each pickup location.
304
and if item can be transferred to each pickup location.
304
305
305
=cut
306
=cut
306
307
Lines 310-316 sub pickup_locations { Link Here
310
    my $patron = $params->{patron};
311
    my $patron = $params->{patron};
311
312
312
    my $circ_control_branch =
313
    my $circ_control_branch =
313
      C4::Circulation::_GetCircControlBranch( $self->unblessed(), $patron );
314
      C4::Reserves::GetReservesControlBranch( $self->unblessed(), $patron->unblessed );
314
    my $branchitemrule =
315
    my $branchitemrule =
315
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
316
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
316
317
Lines 345-350 sub pickup_locations { Link Here
345
            push @pickup_locations, $library->unblessed;
346
            push @pickup_locations, $library->unblessed;
346
        }
347
        }
347
    }
348
    }
349
348
    return wantarray ? @pickup_locations : \@pickup_locations;
350
    return wantarray ? @pickup_locations : \@pickup_locations;
349
}
351
}
350
352
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-10 / +10 lines)
Lines 425-434 Link Here
425
                                <label for="pickup">Pickup at:</label>
425
                                <label for="pickup">Pickup at:</label>
426
                                <select name="pickup" size="1" id="pickup">
426
                                <select name="pickup" size="1" id="pickup">
427
                                    [% UNLESS ( multi_hold ) %]
427
                                    [% UNLESS ( multi_hold ) %]
428
				        [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
428
                                        [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
429
				    [% ELSE %]
429
                                    [% ELSE %]
430
				        [% PROCESS options_for_libraries libraries => Branches.all({ selected => pickup, search_params => { pickup_location => 1 } }) %]
430
                                        [% PROCESS options_for_libraries libraries => Branches.all({ selected => pickup, search_params => { pickup_location => 1 } }) %]
431
				    [% END %]
431
                                    [% END %]
432
                                </select>
432
                                </select>
433
                            </li>
433
                            </li>
434
434
Lines 544-550 Link Here
544
                                                <th>Vol no.</th>
544
                                                <th>Vol no.</th>
545
                                            [% END %]
545
                                            [% END %]
546
                                            <th class="title-string">Information</th>
546
                                            <th class="title-string">Information</th>
547
					    <th class="title-string">Allowed pickup locations</th>
547
                                            <th class="title-string">Allowed pickup locations</th>
548
                                        </tr>
548
                                        </tr>
549
                                    </thead>
549
                                    </thead>
550
                                    <tbody>
550
                                    <tbody>
Lines 581-588 Link Here
581
                                                                        Not holdable
581
                                                                        Not holdable
582
                                                                    [% ELSIF itemloo.not_holdable == 'cannotReserveFromOtherBranches' %]
582
                                                                    [% ELSIF itemloo.not_holdable == 'cannotReserveFromOtherBranches' %]
583
                                                                        Patron is from different library
583
                                                                        Patron is from different library
584
								    [% ELSIF itemloo.not_holdable == 'branchNotInHoldGroup' %]
584
                                                                    [% ELSIF itemloo.not_holdable == 'branchNotInHoldGroup' %]
585
									Cannot place hold from patrons's library
585
                                                                        Cannot place hold from patron's library
586
                                                                    [% ELSIF itemloo.not_holdable == 'itemAlreadyOnHold' %]
586
                                                                    [% ELSIF itemloo.not_holdable == 'itemAlreadyOnHold' %]
587
                                                                        Patron already has hold for this item
587
                                                                        Patron already has hold for this item
588
                                                                    [% ELSIF itemloo.not_holdable == 'cannotBeTransferred' %]
588
                                                                    [% ELSIF itemloo.not_holdable == 'cannotBeTransferred' %]
Lines 680-688 Link Here
680
                                                           <span class="nfl">Not for loan ([% AuthorisedValues.GetByCode( 'NOT_LOAN', itemloo.notforloan ) | html %])</span>
680
                                                           <span class="nfl">Not for loan ([% AuthorisedValues.GetByCode( 'NOT_LOAN', itemloo.notforloan ) | html %])</span>
681
                                                        [% END %]
681
                                                        [% END %]
682
                                                    </td>
682
                                                    </td>
683
						    <td>
683
                                                    <td>
684
						        [% itemloo.pickup_locations | html %]
684
                                                        [% itemloo.pickup_locations | html %]
685
						    </td>
685
                                                    </td>
686
                                                </tr>
686
                                                </tr>
687
                                            [% END # / UNLESS itemloo.hide %]
687
                                            [% END # / UNLESS itemloo.hide %]
688
                                        [% END # /FOREACH itemloo %]
688
                                        [% END # /FOREACH itemloo %]
(-)a/reserve/request.pl (+2 lines)
Lines 564-571 foreach my $biblionumber (@biblionumbers) { Link Here
564
                    $num_available++;
564
                    $num_available++;
565
                    if($branchitemrule->{'hold_fulfillment_policy'} eq 'any' ) {
565
                    if($branchitemrule->{'hold_fulfillment_policy'} eq 'any' ) {
566
                        $item->{pickup_locations} = 'Any library';
566
                        $item->{pickup_locations} = 'Any library';
567
                        $item->{pickup_locations_code} = 'all';
567
                    } else {
568
                    } else {
568
                        $item->{pickup_locations} = join (', ', map { $_->{branchname} } Koha::Items->find($itemnumber)->pickup_locations({ patron => $patron }));
569
                        $item->{pickup_locations} = join (', ', map { $_->{branchname} } Koha::Items->find($itemnumber)->pickup_locations({ patron => $patron }));
570
                        $item->{pickup_locations_code} = join (',', map { $_->{branchcode} } Koha::Items->find($itemnumber)->pickup_locations({ patron => $patron }));
569
                    }
571
                    }
570
572
571
                    push( @available_itemtypes, $item->{itype} );
573
                    push( @available_itemtypes, $item->{itype} );
(-)a/t/db_dependent/Koha/Biblios.t (-306 / +101 lines)
Lines 192-198 $schema->storage->txn_rollback; Link Here
192
192
193
193
194
subtest 'pickup_locations' => sub {
194
subtest 'pickup_locations' => sub {
195
    plan tests => 25;
195
    plan tests => 8;
196
196
197
    $schema->storage->txn_begin;
197
    $schema->storage->txn_begin;
198
198
Lines 221-317 subtest 'pickup_locations' => sub { Link Here
221
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
221
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
222
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
222
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
223
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
223
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
224
    my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
225
    my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
224
226
225
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
226
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
227
228
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
229
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
230
231
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
232
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
233
234
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios' } );
235
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
236
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios' } );
237
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
238
239
    my $item1_1  = Koha::Item->new({
240
        biblionumber     => $biblio1->biblionumber,
241
        biblioitemnumber => $biblioitem1->biblioitemnumber,
242
        homebranch       => $library1->branchcode,
243
        holdingbranch    => $library2->branchcode,
244
        itype            => 'test',
245
        barcode          => "item11barcode",
246
    })->store;
247
248
    my $item1_3  = Koha::Item->new({
249
        biblionumber     => $biblio1->biblionumber,
250
        biblioitemnumber => $biblioitem1->biblioitemnumber,
251
        homebranch       => $library3->branchcode,
252
        holdingbranch    => $library4->branchcode,
253
        itype            => 'test',
254
        barcode          => "item13barcode",
255
    })->store;
256
257
    my $item2_2  = Koha::Item->new({
258
        biblionumber     => $biblio2->biblionumber,
259
        biblioitemnumber => $biblioitem2->biblioitemnumber,
260
        homebranch       => $library2->branchcode,
261
        holdingbranch    => $library1->branchcode,
262
        itype            => 'test',
263
        barcode          => "item22barcode",
264
    })->store;
265
266
    my $item2_3  = Koha::Item->new({
267
        biblionumber     => $biblio2->biblionumber,
268
        biblioitemnumber => $biblioitem2->biblioitemnumber,
269
        homebranch       => $library3->branchcode,
270
        holdingbranch    => $library3->branchcode,
271
        itype            => 'test',
272
        barcode          => "item23barcode",
273
    })->store;
274
275
    my $item2_4  = Koha::Item->new({
276
        biblionumber     => $biblio2->biblionumber,
277
        biblioitemnumber => $biblioitem2->biblioitemnumber,
278
        homebranch       => $library4->branchcode,
279
        holdingbranch    => $library4->branchcode,
280
        itype            => 'test',
281
        barcode          => "item24barcode",
282
    })->store;
283
284
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
285
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
286
287
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
288
289
    #Case 1: holdallowed any, hold_fulfillment_policy any
290
    Koha::CirculationRules->set_rules(
227
    Koha::CirculationRules->set_rules(
291
        {
228
        {
292
            branchcode => undef,
229
            branchcode => $library1->branchcode,
293
            itemtype   => undef,
294
            categorycode => undef,
295
            rules => {
296
                holdallowed => 2,
297
                hold_fulfillment_policy => 'any',
298
                returnbranch => 'any'
299
            }
300
        }
301
    );
302
303
    my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
304
    my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
305
    my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
306
    my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
307
308
309
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations');
310
311
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
312
    Koha::CirculationRules->set_rules(
313
        {
314
            branchcode => undef,
315
            itemtype   => undef,
230
            itemtype   => undef,
316
            categorycode => undef,
231
            categorycode => undef,
317
            rules => {
232
            rules => {
Lines 322-424 subtest 'pickup_locations' => sub { Link Here
322
        }
237
        }
323
    );
238
    );
324
239
325
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
326
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
327
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
328
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
329
330
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations, when item\'s hombebranch equals patron\' homebranch');
331
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
332
333
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
334
    Koha::CirculationRules->set_rules(
240
    Koha::CirculationRules->set_rules(
335
        {
241
        {
336
            branchcode => undef,
242
            branchcode => $library2->branchcode,
337
            itemtype   => undef,
243
            itemtype   => undef,
338
            categorycode => undef,
244
            categorycode => undef,
339
            rules => {
245
            rules => {
340
                holdallowed => 3,
246
                holdallowed => 3,
341
                hold_fulfillment_policy => 'any',
342
                returnbranch => 'any'
343
            }
344
        }
345
    );
346
347
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
348
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
349
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
350
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
351
352
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5, 'Returns all libraries that are pickup_locations, when item\'s hombebranch is in patron\' holdgroup');
353
354
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
355
    Koha::CirculationRules->set_rules(
356
        {
357
            branchcode => undef,
358
            itemtype   => undef,
359
            categorycode => undef,
360
            rules => {
361
                holdallowed => 2,
362
                hold_fulfillment_policy => 'holdgroup',
247
                hold_fulfillment_policy => 'holdgroup',
363
                returnbranch => 'any'
248
                returnbranch => 'any'
364
            }
249
            }
365
        }
250
        }
366
    );
251
    );
367
252
368
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
369
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
370
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
371
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
372
373
    ok(scalar(@pl_1_1) == 3 && scalar(@pl_2_4) == 3 && scalar(@pl_1_4) == 3 && scalar(@pl_2_1) == 3, 'Returns libraries in item\'s holdgroup, and that are pickup_locations');
374
375
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
376
    Koha::CirculationRules->set_rules(
253
    Koha::CirculationRules->set_rules(
377
        {
254
        {
378
            branchcode => undef,
255
            branchcode => $library3->branchcode,
379
            itemtype   => undef,
256
            itemtype   => undef,
380
            categorycode => undef,
257
            categorycode => undef,
381
            rules => {
258
            rules => {
382
                holdallowed => 1,
259
                holdallowed => 3,
383
                hold_fulfillment_policy => 'holdgroup',
260
                hold_fulfillment_policy => 'patrongroup',
384
                returnbranch => 'any'
261
                returnbranch => 'any'
385
            }
262
            }
386
        }
263
        }
387
    );
264
    );
388
265
389
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
390
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
391
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
392
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
393
394
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch equals patron\'s homebranch, and that are pickup_locations');
395
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
396
397
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
398
    Koha::CirculationRules->set_rules(
266
    Koha::CirculationRules->set_rules(
399
        {
267
        {
400
            branchcode => undef,
268
            branchcode => $library4->branchcode,
401
            itemtype   => undef,
269
            itemtype   => undef,
402
            categorycode => undef,
270
            categorycode => undef,
403
            rules => {
271
            rules => {
404
                holdallowed => 3,
272
                holdallowed => 2,
405
                hold_fulfillment_policy => 'holdgroup',
273
                hold_fulfillment_policy => 'holdingbranch',
406
                returnbranch => 'any'
274
                returnbranch => 'any'
407
            }
275
            }
408
        }
276
        }
409
    );
277
    );
410
278
411
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
412
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
413
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
414
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
415
416
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch is included patron\'s holdgroup, and that are pickup_locations');
417
418
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
419
    Koha::CirculationRules->set_rules(
279
    Koha::CirculationRules->set_rules(
420
        {
280
        {
421
            branchcode => undef,
281
            branchcode => $library5->branchcode,
422
            itemtype   => undef,
282
            itemtype   => undef,
423
            categorycode => undef,
283
            categorycode => undef,
424
            rules => {
284
            rules => {
Lines 429-639 subtest 'pickup_locations' => sub { Link Here
429
        }
289
        }
430
    );
290
    );
431
291
432
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
433
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
434
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
435
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
436
437
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns homebranch of items in biblio, that are pickup_locations');
438
439
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
440
    Koha::CirculationRules->set_rules(
292
    Koha::CirculationRules->set_rules(
441
        {
293
        {
442
            branchcode => undef,
294
            branchcode => $library6->branchcode,
443
            itemtype   => undef,
295
            itemtype   => undef,
444
            categorycode => undef,
296
            categorycode => undef,
445
            rules => {
297
            rules => {
446
                holdallowed => 1,
298
                holdallowed => 1,
447
                hold_fulfillment_policy => 'homebranch',
299
                hold_fulfillment_policy => 'holdgroup',
448
                returnbranch => 'any'
300
                returnbranch => 'any'
449
            }
301
            }
450
        }
302
        }
451
    );
303
    );
452
304
453
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
454
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
455
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
456
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
457
458
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Returns homebranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations');
459
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
460
461
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
462
    Koha::CirculationRules->set_rules(
305
    Koha::CirculationRules->set_rules(
463
        {
306
        {
464
            branchcode => undef,
307
            branchcode => $library7->branchcode,
465
            itemtype   => undef,
308
            itemtype   => undef,
466
            categorycode => undef,
309
            categorycode => undef,
467
            rules => {
310
            rules => {
468
                holdallowed => 3,
311
                holdallowed => 3,
469
                hold_fulfillment_policy => 'homebranch',
470
                returnbranch => 'any'
471
            }
472
        }
473
    );
474
475
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
476
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
477
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
478
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
479
480
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio that are within patron\'s holdgroup, and that are pickup_locations');
481
    ok(scalar(@pl_1_4) == 0, 'No pickup locations returned');
482
483
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
484
    Koha::CirculationRules->set_rules(
485
        {
486
            branchcode => undef,
487
            itemtype   => undef,
488
            categorycode => undef,
489
            rules => {
490
                holdallowed => 2,
491
                hold_fulfillment_policy => 'holdingbranch',
312
                hold_fulfillment_policy => 'holdingbranch',
492
                returnbranch => 'any'
313
                returnbranch => 'any'
493
            }
314
            }
494
        }
315
        }
495
    );
316
    );
496
317
497
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
498
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
499
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
500
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
501
502
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns holdingbranch of items in biblio, that are pickup_locations');
503
318
504
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
505
    Koha::CirculationRules->set_rules(
319
    Koha::CirculationRules->set_rules(
506
        {
320
        {
507
            branchcode => undef,
321
            branchcode => $library8->branchcode,
508
            itemtype   => undef,
322
            itemtype   => undef,
509
            categorycode => undef,
323
            categorycode => undef,
510
            rules => {
324
            rules => {
511
                holdallowed => 1,
325
                holdallowed => 2,
512
                hold_fulfillment_policy => 'holdingbranch',
326
                hold_fulfillment_policy => 'patrongroup',
513
                returnbranch => 'any'
327
                returnbranch => 'any'
514
            }
328
            }
515
        }
329
        }
516
    );
330
    );
517
331
518
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
332
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
519
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
333
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
520
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
521
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
522
334
523
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio, whose homebranch equals patron\'s, and that are pickup_locations');
335
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
524
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
336
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
525
337
526
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
338
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
527
    Koha::CirculationRules->set_rules(
339
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
528
        {
340
    my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } );
529
            branchcode => undef,
341
    my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } );
530
            itemtype   => undef,
531
            categorycode => undef,
532
            rules => {
533
                holdallowed => 3,
534
                hold_fulfillment_policy => 'holdingbranch',
535
                returnbranch => 'any'
536
            }
537
        }
538
    );
539
342
540
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
343
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios', value => {title => '1'} } );
541
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
344
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
542
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
345
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios', value => {title => '2'} } );
543
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
346
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
544
347
545
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1, 'Returns holdingbranch of items in biblio, whose homebranch are within patron\'s holdgroup, and that are pickup_locations');
348
    my $item1_1  = Koha::Item->new({
349
        biblionumber     => $biblio1->biblionumber,
350
        biblioitemnumber => $biblioitem1->biblioitemnumber,
351
        homebranch       => $library1->branchcode,
352
        holdingbranch    => $library2->branchcode,
353
        itype            => 'test',
354
        barcode          => "item11barcode",
355
    })->store;
546
356
547
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
357
    my $item1_3  = Koha::Item->new({
358
        biblionumber     => $biblio1->biblionumber,
359
        biblioitemnumber => $biblioitem1->biblioitemnumber,
360
        homebranch       => $library3->branchcode,
361
        holdingbranch    => $library4->branchcode,
362
        itype            => 'test',
363
        barcode          => "item13barcode",
364
    })->store;
548
365
549
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
366
    my $item1_7  = Koha::Item->new({
550
    Koha::CirculationRules->set_rules(
367
        biblionumber     => $biblio1->biblionumber,
551
        {
368
        biblioitemnumber => $biblioitem1->biblioitemnumber,
552
            branchcode => undef,
369
        homebranch       => $library7->branchcode,
553
            itemtype   => undef,
370
        holdingbranch    => $library4->branchcode,
554
            categorycode => undef,
371
        itype            => 'test',
555
            rules => {
372
        barcode          => "item17barcode",
556
                holdallowed => 1,
373
    })->store;
557
                hold_fulfillment_policy => 'any',
558
                returnbranch => 'any'
559
            }
560
        }
561
    );
562
374
563
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
375
    my $item2_2  = Koha::Item->new({
564
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
376
        biblionumber     => $biblio2->biblionumber,
565
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
377
        biblioitemnumber => $biblioitem2->biblioitemnumber,
566
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
378
        homebranch       => $library2->branchcode,
379
        holdingbranch    => $library1->branchcode,
380
        itype            => 'test',
381
        barcode          => "item22barcode",
382
    })->store;
567
383
568
    ok(scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries when item\'s holdingbranch equals patron\'s homebranch, and that are pickup_locations');
384
    my $item2_4  = Koha::Item->new({
569
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
385
        biblionumber     => $biblio2->biblionumber,
386
        biblioitemnumber => $biblioitem2->biblioitemnumber,
387
        homebranch       => $library4->branchcode,
388
        holdingbranch    => $library3->branchcode,
389
        itype            => 'test',
390
        barcode          => "item23barcode",
391
    })->store;
570
392
571
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
393
    my $item2_6  = Koha::Item->new({
572
    Koha::CirculationRules->set_rules(
394
        biblionumber     => $biblio2->biblionumber,
573
        {
395
        biblioitemnumber => $biblioitem2->biblioitemnumber,
574
            branchcode => undef,
396
        homebranch       => $library6->branchcode,
575
            itemtype   => undef,
397
        holdingbranch    => $library4->branchcode,
576
            categorycode => undef,
398
        itype            => 'test',
577
            rules => {
399
        barcode          => "item26barcode",
578
                holdallowed => 1,
400
    })->store;
579
                hold_fulfillment_policy => 'holdgroup',
580
                returnbranch => 'any'
581
            }
582
        }
583
    );
584
401
585
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
402
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } );
586
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
403
    my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
587
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
588
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
589
404
590
    ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose holdingbranch equals patron\'s homebranch, and that are pickup_locations');
405
    my $results = {
591
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
406
        "ItemHomeLibrary-1-1" => 6,
407
        "ItemHomeLibrary-1-8" => 1,
408
        "ItemHomeLibrary-2-1" => 2,
409
        "ItemHomeLibrary-2-8" => 0,
410
        "PatronLibrary-1-1" => 6,
411
        "PatronLibrary-1-8" => 3,
412
        "PatronLibrary-2-1" => 0,
413
        "PatronLibrary-2-8" => 3,
414
    };
592
415
593
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
416
    sub _doTest {
594
    Koha::CirculationRules->set_rules(
417
        my ( $cbranch, $biblio, $patron, $results ) = @_;
595
        {
418
        t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
596
            branchcode => undef,
597
            itemtype   => undef,
598
            categorycode => undef,
599
            rules => {
600
                holdallowed => 1,
601
                hold_fulfillment_policy => 'homebranch',
602
                returnbranch => 'any'
603
            }
604
        }
605
    );
606
419
607
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
420
        my @pl = $biblio->pickup_locations( { patron => $patron} );
608
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
609
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
610
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
611
421
612
    #ok(scalar(@pl_2_4) == 1 && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
422
        ok(scalar(@pl) == $results->{$cbranch.'-'.$biblio->title.'-'.$patron->firstname}, 'ReservesControlBranch: '.$cbranch.', biblio'.$biblio->title.', patron'.$patron->firstname.' should return '.$results->{$cbranch.'-'.$biblio->title.'-'.$patron->firstname}.' but returns '.scalar(@pl));
613
    ok(scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio whose holdingbranch equals patron\'s homebranch, and that are pickup_locations');
423
    }
614
    ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned');
615
424
616
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
425
    foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') {
617
    Koha::CirculationRules->set_rules(
426
        foreach my $biblio ($biblio1, $biblio2) {
618
        {
427
            foreach my $patron ($patron1, $patron8) {
619
            branchcode => undef,
428
                _doTest($cbranch, $biblio, $patron, $results);
620
            itemtype   => undef,
621
            categorycode => undef,
622
            rules => {
623
                holdallowed => 1,
624
                hold_fulfillment_policy => 'holdingbranch',
625
                returnbranch => 'any'
626
            }
429
            }
627
        }
430
        }
628
    );
431
    }
629
630
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
631
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
632
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
633
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
634
635
    ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations');
636
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
637
432
638
    $schema->storage->txn_rollback;
433
    $schema->storage->txn_rollback;
639
};
434
};
(-)a/t/db_dependent/Koha/Items.t (-359 / +96 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation;
25
use C4::Circulation;
Lines 188-194 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
188
$schema->storage->txn_rollback;
188
$schema->storage->txn_rollback;
189
189
190
subtest 'pickup_locations' => sub {
190
subtest 'pickup_locations' => sub {
191
    plan tests => 33;
191
    plan tests => 60;
192
192
193
    $schema->storage->txn_begin;
193
    $schema->storage->txn_begin;
194
194
Lines 228-235 subtest 'pickup_locations' => sub { Link Here
228
        biblioitemnumber => $biblioitem->{biblioitemnumber},
228
        biblioitemnumber => $biblioitem->{biblioitemnumber},
229
        homebranch       => $library1->branchcode,
229
        homebranch       => $library1->branchcode,
230
        holdingbranch    => $library2->branchcode,
230
        holdingbranch    => $library2->branchcode,
231
        barcode          => '1',
231
        itype            => 'test',
232
        itype            => 'test',
232
        barcode          => "item1barcode",
233
    })->store;
233
    })->store;
234
234
235
    my $item3  = Koha::Item->new({
235
    my $item3  = Koha::Item->new({
Lines 237-607 subtest 'pickup_locations' => sub { Link Here
237
        biblioitemnumber => $biblioitem->{biblioitemnumber},
237
        biblioitemnumber => $biblioitem->{biblioitemnumber},
238
        homebranch       => $library3->branchcode,
238
        homebranch       => $library3->branchcode,
239
        holdingbranch    => $library4->branchcode,
239
        holdingbranch    => $library4->branchcode,
240
        barcode          => '3',
240
        itype            => 'test',
241
        itype            => 'test',
241
        barcode          => "item3barcode",
242
    })->store;
242
    })->store;
243
243
244
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
244
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
245
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
245
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
246
246
247
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
247
    my $results = {
248
248
        "1-1-1-any" => 3,
249
    #Case 1: holdallowed any, hold_fulfillment_policy any
249
        "1-1-1-holdgroup" => 2,
250
    Koha::CirculationRules->set_rules(
250
        "1-1-1-patrongroup" => 2,
251
        {
251
        "1-1-1-homebranch" => 1,
252
            branchcode => undef,
252
        "1-1-1-holdingbranch" => 1,
253
            itemtype   => undef,
253
        "1-1-2-any" => 3,
254
            categorycode => undef,
254
        "1-1-2-holdgroup" => 2,
255
            rules => {
255
        "1-1-2-patrongroup" => 2,
256
                holdallowed => 2,
256
        "1-1-2-homebranch" => 1,
257
                hold_fulfillment_policy => 'any',
257
        "1-1-2-holdingbranch" => 1,
258
                returnbranch => 'any'
258
        "1-1-3-any" => 3,
259
        "1-1-3-holdgroup" => 2,
260
        "1-1-3-patrongroup" => 2,
261
        "1-1-3-homebranch" => 1,
262
        "1-1-3-holdingbranch" => 1,
263
        "1-4-1-any" => 0,
264
        "1-4-1-holdgroup" => 0,
265
        "1-4-1-patrongroup" => 0,
266
        "1-4-1-homebranch" => 0,
267
        "1-4-1-holdingbranch" => 0,
268
        "1-4-2-any" => 3,
269
        "1-4-2-holdgroup" => 2,
270
        "1-4-2-patrongroup" => 1,
271
        "1-4-2-homebranch" => 1,
272
        "1-4-2-holdingbranch" => 1,
273
        "1-4-3-any" => 0,
274
        "1-4-3-holdgroup" => 0,
275
        "1-4-3-patrongroup" => 0,
276
        "1-4-3-homebranch" => 0,
277
        "1-4-3-holdingbranch" => 0,
278
        "3-1-1-any" => 0,
279
        "3-1-1-holdgroup" => 0,
280
        "3-1-1-patrongroup" => 0,
281
        "3-1-1-homebranch" => 0,
282
        "3-1-1-holdingbranch" => 0,
283
        "3-1-2-any" => 3,
284
        "3-1-2-holdgroup" => 1,
285
        "3-1-2-patrongroup" => 2,
286
        "3-1-2-homebranch" => 0,
287
        "3-1-2-holdingbranch" => 1,
288
        "3-1-3-any" => 0,
289
        "3-1-3-holdgroup" => 0,
290
        "3-1-3-patrongroup" => 0,
291
        "3-1-3-homebranch" => 0,
292
        "3-1-3-holdingbranch" => 0,
293
        "3-4-1-any" => 0,
294
        "3-4-1-holdgroup" => 0,
295
        "3-4-1-patrongroup" => 0,
296
        "3-4-1-homebranch" => 0,
297
        "3-4-1-holdingbranch" => 0,
298
        "3-4-2-any" => 3,
299
        "3-4-2-holdgroup" => 1,
300
        "3-4-2-patrongroup" => 1,
301
        "3-4-2-homebranch" => 0,
302
        "3-4-2-holdingbranch" => 1,
303
        "3-4-3-any" => 3,
304
        "3-4-3-holdgroup" => 1,
305
        "3-4-3-patrongroup" => 1,
306
        "3-4-3-homebranch" => 0,
307
        "3-4-3-holdingbranch" => 1
308
    };
309
310
    sub _doTest {
311
        my ( $item, $patron, $ha, $hfp, $results ) = @_;
312
313
        Koha::CirculationRules->set_rules(
314
            {
315
                branchcode => undef,
316
                itemtype   => undef,
317
                categorycode => undef,
318
                rules => {
319
                    holdallowed => $ha,
320
                    hold_fulfillment_policy => $hfp,
321
                    returnbranch => 'any'
322
                }
259
            }
323
            }
260
        }
324
        );
261
    );
325
        my @pl = $item->pickup_locations( { patron => $patron} );
262
326
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
263
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
264
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
265
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
266
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
267
268
    ok(scalar(@pl_1_1) == scalar(@pl_1_4) && scalar(@pl_1_1) == scalar(@pl_3_1) && scalar(@pl_1_1) == scalar(@pl_3_4), 'All combinations of patron/item renders the same number of locations');
269
270
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
271
    Koha::CirculationRules->set_rules(
272
        {
273
            branchcode => undef,
274
            itemtype   => undef,
275
            categorycode => undef,
276
            rules => {
277
                holdallowed => 1,
278
                hold_fulfillment_policy => 'any',
279
                returnbranch => 'any'
280
            }
281
        }
282
    );
283
284
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
285
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
286
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
287
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
288
289
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
290
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
291
292
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
293
    Koha::CirculationRules->set_rules(
294
        {
295
            branchcode => undef,
296
            itemtype   => undef,
297
            categorycode => undef,
298
            rules => {
299
                holdallowed => 3,
300
                hold_fulfillment_policy => 'any',
301
                returnbranch => 'any'
302
            }
303
        }
304
    );
305
306
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
307
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
308
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
309
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
310
311
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
312
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
313
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
314
315
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
316
    Koha::CirculationRules->set_rules(
317
        {
318
            branchcode => undef,
319
            itemtype   => undef,
320
            categorycode => undef,
321
            rules => {
322
                holdallowed => 2,
323
                hold_fulfillment_policy => 'holdgroup',
324
                returnbranch => 'any'
325
            }
326
        }
327
    );
328
327
329
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
328
        ok(scalar(@pl) == $results->{$item->barcode.'-'.$patron->firstname.'-'.$ha.'-'.$hfp}, 'item'.$item->barcode.', patron'.$patron->firstname.', holdallowed: '.$ha_value.', hold_fulfillment_policy: '.$hfp.' should return '.$results->{$item->barcode.'-'.$patron->firstname.'-'.$ha.'-'.$hfp}.' but returns '.scalar(@pl));
330
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
329
    }
331
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
332
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
333
334
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2, 'Pickup locations for item 1 renders all libraries in items\'s holdgroup that are pickup_locations');
335
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1, 'Pickup locations for item 3 renders all libraries in items\'s holdgroup that are pickup_locations');
336
337
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
338
    Koha::CirculationRules->set_rules(
339
        {
340
            branchcode => undef,
341
            itemtype   => undef,
342
            categorycode => undef,
343
            rules => {
344
                holdallowed => 1,
345
                hold_fulfillment_policy => 'holdgroup',
346
                returnbranch => 'any'
347
            }
348
        }
349
    );
350
351
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
352
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
353
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
354
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
355
356
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
357
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
358
359
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
360
    Koha::CirculationRules->set_rules(
361
        {
362
            branchcode => undef,
363
            itemtype   => undef,
364
            categorycode => undef,
365
            rules => {
366
                holdallowed => 3,
367
                hold_fulfillment_policy => 'holdgroup',
368
                returnbranch => 'any'
369
            }
370
        }
371
    );
372
373
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
374
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
375
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
376
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
377
378
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
379
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
380
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
381
382
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
383
    Koha::CirculationRules->set_rules(
384
        {
385
            branchcode => undef,
386
            itemtype   => undef,
387
            categorycode => undef,
388
            rules => {
389
                holdallowed => 2,
390
                hold_fulfillment_policy => 'homebranch',
391
                returnbranch => 'any'
392
            }
393
        }
394
    );
395
396
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
397
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
398
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
399
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
400
401
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_1_4[0]->{branchcode} eq $library1->id, 'Pickup locations for item 1 renders item\'s homelibrary');
402
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
403
404
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
405
    Koha::CirculationRules->set_rules(
406
        {
407
            branchcode => undef,
408
            itemtype   => undef,
409
            categorycode => undef,
410
            rules => {
411
                holdallowed => 1,
412
                hold_fulfillment_policy => 'homebranch',
413
                returnbranch => 'any'
414
            }
415
        }
416
    );
417
418
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
419
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
420
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
421
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
422
423
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
424
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
425
426
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
427
    Koha::CirculationRules->set_rules(
428
        {
429
            branchcode => undef,
430
            itemtype   => undef,
431
            categorycode => undef,
432
            rules => {
433
                holdallowed => 3,
434
                hold_fulfillment_policy => 'homebranch',
435
                returnbranch => 'any'
436
            }
437
        }
438
    );
439
440
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
441
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
442
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
443
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
444
445
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
446
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
447
448
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
449
    Koha::CirculationRules->set_rules(
450
        {
451
            branchcode => undef,
452
            itemtype   => undef,
453
            categorycode => undef,
454
            rules => {
455
                holdallowed => 2,
456
                hold_fulfillment_policy => 'holdingbranch',
457
                returnbranch => 'any'
458
            }
459
        }
460
    );
461
462
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
463
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
464
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
465
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
466
467
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode && $pl_1_4[0]->{branchcode} eq $library2->branchcode, 'Pickup locations for item 1 renders item\'s holding branch');
468
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1 && $pl_3_1[0]->{branchcode} eq $library4->branchcode && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup locations for item 3 renders item\'s holding branch');
469
470
471
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
472
    Koha::CirculationRules->set_rules(
473
        {
474
            branchcode => undef,
475
            itemtype   => undef,
476
            categorycode => undef,
477
            rules => {
478
                holdallowed => 1,
479
                hold_fulfillment_policy => 'holdingbranch',
480
                returnbranch => 'any'
481
            }
482
        }
483
    );
484
485
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
486
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
487
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
488
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
489
490
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
491
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
492
493
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
494
    Koha::CirculationRules->set_rules(
495
        {
496
            branchcode => undef,
497
            itemtype   => undef,
498
            categorycode => undef,
499
            rules => {
500
                holdallowed => 3,
501
                hold_fulfillment_policy => 'holdingbranch',
502
                returnbranch => 'any'
503
            }
504
        }
505
    );
506
507
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
508
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
509
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
510
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
511
512
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
513
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
514
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
515
516
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
517
518
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
519
    Koha::CirculationRules->set_rules(
520
        {
521
            branchcode => undef,
522
            itemtype   => undef,
523
            categorycode => undef,
524
            rules => {
525
                holdallowed => 1,
526
                hold_fulfillment_policy => 'any',
527
                returnbranch => 'any'
528
            }
529
        }
530
    );
531
330
532
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
533
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
534
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
535
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
536
537
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
538
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
539
540
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
541
    Koha::CirculationRules->set_rules(
542
        {
543
            branchcode => undef,
544
            itemtype   => undef,
545
            categorycode => undef,
546
            rules => {
547
                holdallowed => 1,
548
                hold_fulfillment_policy => 'holdgroup',
549
                returnbranch => 'any'
550
            }
551
        }
552
    );
553
331
554
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
332
    foreach my $item ($item1, $item3) {
555
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
333
        foreach my $patron ($patron1, $patron4) {
556
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
334
            #holdallowed 1: homebranch, 2: any, 3: holdgroup
557
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
335
            foreach my $ha (1, 2, 3) {
558
336
                foreach my $hfp ('any', 'holdgroup', 'patrongroup', 'homebranch', 'holdingbranch') {
559
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
337
                    _doTest($item, $patron, $ha, $hfp, $results);
560
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
338
                }
561
562
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
563
    Koha::CirculationRules->set_rules(
564
        {
565
            branchcode => undef,
566
            itemtype   => undef,
567
            categorycode => undef,
568
            rules => {
569
                holdallowed => 1,
570
                hold_fulfillment_policy => 'homebranch',
571
                returnbranch => 'any'
572
            }
339
            }
573
        }
340
        }
574
    );
341
    }
575
576
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
577
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
578
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
579
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
580
581
    #ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
582
    ok(scalar(@pl_3_4) == 0 && scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any combination of patron/item renders no locations');
583
584
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
585
    Koha::CirculationRules->set_rules(
586
        {
587
            branchcode => undef,
588
            itemtype   => undef,
589
            categorycode => undef,
590
            rules => {
591
                holdallowed => 1,
592
                hold_fulfillment_policy => 'holdingbranch',
593
                returnbranch => 'any'
594
            }
595
        }
596
    );
597
598
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
599
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
600
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
601
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
602
603
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
604
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
605
342
606
    $schema->storage->txn_rollback;
343
    $schema->storage->txn_rollback;
607
};
344
};
(-)a/t/db_dependent/Koha/Libraries.t (-22 / +36 lines)
Lines 31-36 use Koha::Items; Link Here
31
use Koha::Library;
31
use Koha::Library;
32
use Koha::Libraries;
32
use Koha::Libraries;
33
use Koha::Database;
33
use Koha::Database;
34
use Koha::CirculationRules;
34
35
35
use t::lib::Mocks;
36
use t::lib::Mocks;
36
use t::lib::TestBuilder;
37
use t::lib::TestBuilder;
Lines 90-95 isa_ok( $srstages->next, 'Koha::StockRotationStage', "Relationship correctly cre Link Here
90
subtest 'pickup_locations' => sub {
91
subtest 'pickup_locations' => sub {
91
    plan tests => 2;
92
    plan tests => 2;
92
93
94
    Koha::CirculationRules->set_rules(
95
        {
96
            branchcode => undef,
97
            itemtype   => undef,
98
            categorycode => undef,
99
            rules => {
100
                holdallowed => 2,
101
                hold_fulfillment_policy => 'any',
102
                returnbranch => 'any'
103
            }
104
        }
105
    );
106
93
    my $from = Koha::Library->new({
107
    my $from = Koha::Library->new({
94
        branchcode => 'zzzfrom',
108
        branchcode => 'zzzfrom',
95
        branchname => 'zzzfrom',
109
        branchname => 'zzzfrom',
Lines 112-117 subtest 'pickup_locations' => sub { Link Here
112
    my $item1 = $builder->build_sample_item({%$item_info});
126
    my $item1 = $builder->build_sample_item({%$item_info});
113
    my $item2 = $builder->build_sample_item({%$item_info});
127
    my $item2 = $builder->build_sample_item({%$item_info});
114
    my $item3 = $builder->build_sample_item({%$item_info});
128
    my $item3 = $builder->build_sample_item({%$item_info});
129
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $from->branchcode } } );
115
130
116
    subtest 'UseBranchTransferLimits = OFF' => sub {
131
    subtest 'UseBranchTransferLimits = OFF' => sub {
117
        plan tests => 5;
132
        plan tests => 5;
Lines 128-134 subtest 'pickup_locations' => sub { Link Here
128
        my $total_pickup = Koha::Libraries->search({
143
        my $total_pickup = Koha::Libraries->search({
129
            pickup_location => 1
144
            pickup_location => 1
130
        })->count;
145
        })->count;
131
        my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
146
        my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
132
        is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system '
147
        is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system '
133
           .'preference UseBranchTransferLimits is switched OFF,');
148
           .'preference UseBranchTransferLimits is switched OFF,');
134
        is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations '
149
        is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations '
Lines 136-150 subtest 'pickup_locations' => sub { Link Here
136
151
137
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
152
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
138
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
153
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
139
        $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
154
        $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1  });
140
        is(@{$pickup}, $total_pickup, '...when '
155
        is(@{$pickup}, $total_pickup, '...when '
141
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 1');
156
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 1');
142
        t::lib::Mocks::mock_preference('item-level_itypes', 0);
157
        t::lib::Mocks::mock_preference('item-level_itypes', 0);
143
        $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
158
        $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1  });
144
        is(@{$pickup}, $total_pickup, '...as well as when '
159
        is(@{$pickup}, $total_pickup, '...as well as when '
145
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 0');
160
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 0');
146
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
161
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
147
        $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
162
        $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1  });
148
        is(@{$pickup}, $total_pickup, '...as well as when '
163
        is(@{$pickup}, $total_pickup, '...as well as when '
149
           .'BranchTransferLimitsType = ccode');
164
           .'BranchTransferLimitsType = ccode');
150
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
165
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 174-180 subtest 'pickup_locations' => sub { Link Here
174
               'Given all items of a biblio have same the itemtype,');
189
               'Given all items of a biblio have same the itemtype,');
175
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
190
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
176
               .'is an existing transfer limit for that itemtype,');
191
               .'is an existing transfer limit for that itemtype,');
177
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber});
192
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
178
            my $found = 0;
193
            my $found = 0;
179
            foreach my $lib (@{$pickup}) {
194
            foreach my $lib (@{$pickup}) {
180
                if ($lib->{'branchcode'} eq $limit->toBranch) {
195
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 183-189 subtest 'pickup_locations' => sub { Link Here
183
            }
198
            }
184
            is($found, 0, 'Then the to-library of which the limit applies for, '
199
            is($found, 0, 'Then the to-library of which the limit applies for, '
185
               .'is not included in the list of pickup libraries.');
200
               .'is not included in the list of pickup libraries.');
186
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
201
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
187
            $found = 0;
202
            $found = 0;
188
            foreach my $lib (@{$pickup}) {
203
            foreach my $lib (@{$pickup}) {
189
                if ($lib->{'branchcode'} eq $limit->toBranch) {
204
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 203-209 subtest 'pickup_locations' => sub { Link Here
203
            is(Koha::Item::Transfer::Limits->search({
218
            is(Koha::Item::Transfer::Limits->search({
204
                itemtype => $item2->effective_itemtype })->count, 0, 'and it is'
219
                itemtype => $item2->effective_itemtype })->count, 0, 'and it is'
205
               .' not restricted by transfer limits,');
220
               .' not restricted by transfer limits,');
206
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
221
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1  });
207
            $found = 0;
222
            $found = 0;
208
            foreach my $lib (@{$pickup}) {
223
            foreach my $lib (@{$pickup}) {
209
                if ($lib->{'branchcode'} eq $limit->toBranch) {
224
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 212-218 subtest 'pickup_locations' => sub { Link Here
212
            }
227
            }
213
            is($found, 1, 'Then the to-library of which the limit applies for, '
228
            is($found, 1, 'Then the to-library of which the limit applies for, '
214
               .'is included in the list of pickup libraries.');
229
               .'is included in the list of pickup libraries.');
215
            $pickup = Koha::Libraries->pickup_locations({ item => $item2 });
230
            $pickup = Koha::Libraries->pickup_locations({ item => $item2, patron => $patron1 });
216
            $found = 0;
231
            $found = 0;
217
            foreach my $lib (@{$pickup}) {
232
            foreach my $lib (@{$pickup}) {
218
                if ($lib->{'branchcode'} eq $limit->toBranch) {
233
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 222-228 subtest 'pickup_locations' => sub { Link Here
222
            is($found, 1, 'The same applies when asking pickup locations of '
237
            is($found, 1, 'The same applies when asking pickup locations of '
223
               .'a that particular item.');
238
               .'a that particular item.');
224
            Koha::Item::Transfer::Limits->delete;
239
            Koha::Item::Transfer::Limits->delete;
225
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
240
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
226
            $found = 0;
241
            $found = 0;
227
            foreach my $lib (@{$pickup}) {
242
            foreach my $lib (@{$pickup}) {
228
                if ($lib->{'branchcode'} eq $limit->toBranch) {
243
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 231-237 subtest 'pickup_locations' => sub { Link Here
231
            }
246
            }
232
            is($found, 1, 'Given we deleted transfer limit, the previously '
247
            is($found, 1, 'Given we deleted transfer limit, the previously '
233
               .'transfer-limited library is included in the list.');
248
               .'transfer-limited library is included in the list.');
234
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
249
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
235
            $found = 0;
250
            $found = 0;
236
            foreach my $lib (@{$pickup}) {
251
            foreach my $lib (@{$pickup}) {
237
                if ($lib->{'branchcode'} eq $limit->toBranch) {
252
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 260-266 subtest 'pickup_locations' => sub { Link Here
260
               'Given items use biblio-level itemtype,');
275
               'Given items use biblio-level itemtype,');
261
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
276
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
262
               .'is an existing transfer limit for that itemtype,');
277
               .'is an existing transfer limit for that itemtype,');
263
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
278
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
264
            my $found = 0;
279
            my $found = 0;
265
            foreach my $lib (@{$pickup}) {
280
            foreach my $lib (@{$pickup}) {
266
                if ($lib->{'branchcode'} eq $limit->toBranch) {
281
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 269-275 subtest 'pickup_locations' => sub { Link Here
269
            }
284
            }
270
            is($found, 0, 'Then the to-library of which the limit applies for, '
285
            is($found, 0, 'Then the to-library of which the limit applies for, '
271
               .'is not included in the list of pickup libraries.');
286
               .'is not included in the list of pickup libraries.');
272
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
287
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
273
            $found = 0;
288
            $found = 0;
274
            foreach my $lib (@{$pickup}) {
289
            foreach my $lib (@{$pickup}) {
275
                if ($lib->{'branchcode'} eq $limit->toBranch) {
290
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 284-290 subtest 'pickup_locations' => sub { Link Here
284
            is(@{$pickup}, $others, 'However, the number of other pickup '
299
            is(@{$pickup}, $others, 'However, the number of other pickup '
285
               .'libraries is correct.');
300
               .'libraries is correct.');
286
            Koha::Item::Transfer::Limits->delete;
301
            Koha::Item::Transfer::Limits->delete;
287
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
302
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
288
            $found = 0;
303
            $found = 0;
289
            foreach my $lib (@{$pickup}) {
304
            foreach my $lib (@{$pickup}) {
290
                if ($lib->{'branchcode'} eq $limit->toBranch) {
305
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 301-307 subtest 'pickup_locations' => sub { Link Here
301
            ok($item1->itype ne $item1->effective_itemtype
316
            ok($item1->itype ne $item1->effective_itemtype
302
               && $limit->itemtype eq $item1->itype, 'Given we have added a limit'
317
               && $limit->itemtype eq $item1->itype, 'Given we have added a limit'
303
               .' matching ITEM-level itemtype,');
318
               .' matching ITEM-level itemtype,');
304
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
319
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
305
            $found = 0;
320
            $found = 0;
306
            foreach my $lib (@{$pickup}) {
321
            foreach my $lib (@{$pickup}) {
307
                if ($lib->{'branchcode'} eq $limit->toBranch) {
322
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 310-316 subtest 'pickup_locations' => sub { Link Here
310
            }
325
            }
311
            is($found, 1, 'Then the limited branch is still included as a pickup'
326
            is($found, 1, 'Then the limited branch is still included as a pickup'
312
               .' library.');
327
               .' library.');
313
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
328
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
314
            $found = 0;
329
            $found = 0;
315
            foreach my $lib (@{$pickup}) {
330
            foreach my $lib (@{$pickup}) {
316
                if ($lib->{'branchcode'} eq $limit->toBranch) {
331
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 337-343 subtest 'pickup_locations' => sub { Link Here
337
352
338
            is($limit->ccode, $item1->ccode, 'Given there '
353
            is($limit->ccode, $item1->ccode, 'Given there '
339
               .'is an existing transfer limit for that ccode,');
354
               .'is an existing transfer limit for that ccode,');
340
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
355
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
341
            my $found = 0;
356
            my $found = 0;
342
            foreach my $lib (@{$pickup}) {
357
            foreach my $lib (@{$pickup}) {
343
                if ($lib->{'branchcode'} eq $limit->toBranch) {
358
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 346-352 subtest 'pickup_locations' => sub { Link Here
346
            }
361
            }
347
            is($found, 0, 'Then the to-library of which the limit applies for, '
362
            is($found, 0, 'Then the to-library of which the limit applies for, '
348
               .'is not included in the list of pickup libraries.');
363
               .'is not included in the list of pickup libraries.');
349
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
364
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
350
            $found = 0;
365
            $found = 0;
351
            foreach my $lib (@{$pickup}) {
366
            foreach my $lib (@{$pickup}) {
352
                if ($lib->{'branchcode'} eq $limit->toBranch) {
367
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 366-372 subtest 'pickup_locations' => sub { Link Here
366
            is(Koha::Item::Transfer::Limits->search({
381
            is(Koha::Item::Transfer::Limits->search({
367
                ccode => $item3->ccode })->count, 0, 'and it is'
382
                ccode => $item3->ccode })->count, 0, 'and it is'
368
               .' not restricted by transfer limits,');
383
               .' not restricted by transfer limits,');
369
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
384
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
370
            $found = 0;
385
            $found = 0;
371
            foreach my $lib (@{$pickup}) {
386
            foreach my $lib (@{$pickup}) {
372
                if ($lib->{'branchcode'} eq $limit->toBranch) {
387
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 375-381 subtest 'pickup_locations' => sub { Link Here
375
            }
390
            }
376
            is($found, 1, 'Then the to-library of which the limit applies for, '
391
            is($found, 1, 'Then the to-library of which the limit applies for, '
377
               .'is included in the list of pickup libraries.');
392
               .'is included in the list of pickup libraries.');
378
            $pickup = Koha::Libraries->pickup_locations({ item => $item3 });
393
            $pickup = Koha::Libraries->pickup_locations({ item => $item3, patron => $patron1 });
379
            $found = 0;
394
            $found = 0;
380
            foreach my $lib (@{$pickup}) {
395
            foreach my $lib (@{$pickup}) {
381
                if ($lib->{'branchcode'} eq $limit->toBranch) {
396
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 385-391 subtest 'pickup_locations' => sub { Link Here
385
            is($found, 1, 'The same applies when asking pickup locations of '
400
            is($found, 1, 'The same applies when asking pickup locations of '
386
               .'a that particular item.');
401
               .'a that particular item.');
387
            Koha::Item::Transfer::Limits->delete;
402
            Koha::Item::Transfer::Limits->delete;
388
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber });
403
            $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
389
            $found = 0;
404
            $found = 0;
390
            foreach my $lib (@{$pickup}) {
405
            foreach my $lib (@{$pickup}) {
391
                if ($lib->{'branchcode'} eq $limit->toBranch) {
406
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 394-400 subtest 'pickup_locations' => sub { Link Here
394
            }
409
            }
395
            is($found, 1, 'Given we deleted transfer limit, the previously '
410
            is($found, 1, 'Given we deleted transfer limit, the previously '
396
               .'transfer-limited library is included in the list.');
411
               .'transfer-limited library is included in the list.');
397
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
412
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
398
            $found = 0;
413
            $found = 0;
399
            foreach my $lib (@{$pickup}) {
414
            foreach my $lib (@{$pickup}) {
400
                if ($lib->{'branchcode'} eq $limit->toBranch) {
415
                if ($lib->{'branchcode'} eq $limit->toBranch) {
401
- 

Return to bug 22284