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

(-)a/Koha/Biblio.pm (-1 / +1 lines)
Lines 175-181 sub can_be_transferred { Link Here
175
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
175
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
176
176
177
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
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)
178
and if item can be transfered to each pickup location.
178
and if item can be transferred to each pickup location.
179
179
180
=cut
180
=cut
181
181
(-)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 299-305 sub can_be_transferred { Link Here
299
@pickup_locations = $item->pickup_locations( {patron => $patron } )
300
@pickup_locations = $item->pickup_locations( {patron => $patron } )
300
301
301
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)
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)
302
and if item can be transfered to each pickup location.
303
and if item can be transferred to each pickup location.
303
304
304
=cut
305
=cut
305
306
Lines 309-315 sub pickup_locations { Link Here
309
    my $patron = $params->{patron};
310
    my $patron = $params->{patron};
310
311
311
    my $circ_control_branch =
312
    my $circ_control_branch =
312
      C4::Circulation::_GetCircControlBranch( $self->unblessed(), $patron );
313
      C4::Reserves::GetReservesControlBranch( $self->unblessed(), $patron->unblessed );
313
    my $branchitemrule =
314
    my $branchitemrule =
314
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
315
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
315
316
Lines 344-349 sub pickup_locations { Link Here
344
            push @pickup_locations, $library->unblessed;
345
            push @pickup_locations, $library->unblessed;
345
        }
346
        }
346
    }
347
    }
348
347
    return wantarray ? @pickup_locations : \@pickup_locations;
349
    return wantarray ? @pickup_locations : \@pickup_locations;
348
}
350
}
349
351
(-)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 220-226 $schema->storage->txn_rollback; Link Here
220
220
221
221
222
subtest 'pickup_locations' => sub {
222
subtest 'pickup_locations' => sub {
223
    plan tests => 25;
223
    plan tests => 8;
224
224
225
    $schema->storage->txn_begin;
225
    $schema->storage->txn_begin;
226
226
Lines 249-345 subtest 'pickup_locations' => sub { Link Here
249
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
249
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
250
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
250
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
251
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
251
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
252
    my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
253
    my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
252
254
253
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
254
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
255
256
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
257
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
258
259
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
260
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
261
262
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios' } );
263
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
264
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios' } );
265
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
266
267
    my $item1_1  = Koha::Item->new({
268
        biblionumber     => $biblio1->biblionumber,
269
        biblioitemnumber => $biblioitem1->biblioitemnumber,
270
        homebranch       => $library1->branchcode,
271
        holdingbranch    => $library2->branchcode,
272
        itype            => 'test',
273
        barcode          => "item11barcode",
274
    })->store;
275
276
    my $item1_3  = Koha::Item->new({
277
        biblionumber     => $biblio1->biblionumber,
278
        biblioitemnumber => $biblioitem1->biblioitemnumber,
279
        homebranch       => $library3->branchcode,
280
        holdingbranch    => $library4->branchcode,
281
        itype            => 'test',
282
        barcode          => "item13barcode",
283
    })->store;
284
285
    my $item2_2  = Koha::Item->new({
286
        biblionumber     => $biblio2->biblionumber,
287
        biblioitemnumber => $biblioitem2->biblioitemnumber,
288
        homebranch       => $library2->branchcode,
289
        holdingbranch    => $library1->branchcode,
290
        itype            => 'test',
291
        barcode          => "item22barcode",
292
    })->store;
293
294
    my $item2_3  = Koha::Item->new({
295
        biblionumber     => $biblio2->biblionumber,
296
        biblioitemnumber => $biblioitem2->biblioitemnumber,
297
        homebranch       => $library3->branchcode,
298
        holdingbranch    => $library3->branchcode,
299
        itype            => 'test',
300
        barcode          => "item23barcode",
301
    })->store;
302
303
    my $item2_4  = Koha::Item->new({
304
        biblionumber     => $biblio2->biblionumber,
305
        biblioitemnumber => $biblioitem2->biblioitemnumber,
306
        homebranch       => $library4->branchcode,
307
        holdingbranch    => $library4->branchcode,
308
        itype            => 'test',
309
        barcode          => "item24barcode",
310
    })->store;
311
312
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
313
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
314
315
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
316
317
    #Case 1: holdallowed any, hold_fulfillment_policy any
318
    Koha::CirculationRules->set_rules(
255
    Koha::CirculationRules->set_rules(
319
        {
256
        {
320
            branchcode => undef,
257
            branchcode => $library1->branchcode,
321
            itemtype   => undef,
322
            categorycode => undef,
323
            rules => {
324
                holdallowed => 2,
325
                hold_fulfillment_policy => 'any',
326
                returnbranch => 'any'
327
            }
328
        }
329
    );
330
331
    my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
332
    my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
333
    my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
334
    my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
335
336
337
    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');
338
339
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
340
    Koha::CirculationRules->set_rules(
341
        {
342
            branchcode => undef,
343
            itemtype   => undef,
258
            itemtype   => undef,
344
            categorycode => undef,
259
            categorycode => undef,
345
            rules => {
260
            rules => {
Lines 350-452 subtest 'pickup_locations' => sub { Link Here
350
        }
265
        }
351
    );
266
    );
352
267
353
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
354
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
355
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
356
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
357
358
    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');
359
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
360
361
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
362
    Koha::CirculationRules->set_rules(
268
    Koha::CirculationRules->set_rules(
363
        {
269
        {
364
            branchcode => undef,
270
            branchcode => $library2->branchcode,
365
            itemtype   => undef,
271
            itemtype   => undef,
366
            categorycode => undef,
272
            categorycode => undef,
367
            rules => {
273
            rules => {
368
                holdallowed => 3,
274
                holdallowed => 3,
369
                hold_fulfillment_policy => 'any',
370
                returnbranch => 'any'
371
            }
372
        }
373
    );
374
375
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
376
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
377
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
378
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
379
380
    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');
381
382
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
383
    Koha::CirculationRules->set_rules(
384
        {
385
            branchcode => undef,
386
            itemtype   => undef,
387
            categorycode => undef,
388
            rules => {
389
                holdallowed => 2,
390
                hold_fulfillment_policy => 'holdgroup',
275
                hold_fulfillment_policy => 'holdgroup',
391
                returnbranch => 'any'
276
                returnbranch => 'any'
392
            }
277
            }
393
        }
278
        }
394
    );
279
    );
395
280
396
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
397
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
398
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
399
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
400
401
    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');
402
403
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
404
    Koha::CirculationRules->set_rules(
281
    Koha::CirculationRules->set_rules(
405
        {
282
        {
406
            branchcode => undef,
283
            branchcode => $library3->branchcode,
407
            itemtype   => undef,
284
            itemtype   => undef,
408
            categorycode => undef,
285
            categorycode => undef,
409
            rules => {
286
            rules => {
410
                holdallowed => 1,
287
                holdallowed => 3,
411
                hold_fulfillment_policy => 'holdgroup',
288
                hold_fulfillment_policy => 'patrongroup',
412
                returnbranch => 'any'
289
                returnbranch => 'any'
413
            }
290
            }
414
        }
291
        }
415
    );
292
    );
416
293
417
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
418
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
419
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
420
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
421
422
    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');
423
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
424
425
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
426
    Koha::CirculationRules->set_rules(
294
    Koha::CirculationRules->set_rules(
427
        {
295
        {
428
            branchcode => undef,
296
            branchcode => $library4->branchcode,
429
            itemtype   => undef,
297
            itemtype   => undef,
430
            categorycode => undef,
298
            categorycode => undef,
431
            rules => {
299
            rules => {
432
                holdallowed => 3,
300
                holdallowed => 2,
433
                hold_fulfillment_policy => 'holdgroup',
301
                hold_fulfillment_policy => 'holdingbranch',
434
                returnbranch => 'any'
302
                returnbranch => 'any'
435
            }
303
            }
436
        }
304
        }
437
    );
305
    );
438
306
439
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
440
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
441
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
442
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
443
444
    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');
445
446
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
447
    Koha::CirculationRules->set_rules(
307
    Koha::CirculationRules->set_rules(
448
        {
308
        {
449
            branchcode => undef,
309
            branchcode => $library5->branchcode,
450
            itemtype   => undef,
310
            itemtype   => undef,
451
            categorycode => undef,
311
            categorycode => undef,
452
            rules => {
312
            rules => {
Lines 457-667 subtest 'pickup_locations' => sub { Link Here
457
        }
317
        }
458
    );
318
    );
459
319
460
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
461
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
462
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
463
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
464
465
    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');
466
467
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
468
    Koha::CirculationRules->set_rules(
320
    Koha::CirculationRules->set_rules(
469
        {
321
        {
470
            branchcode => undef,
322
            branchcode => $library6->branchcode,
471
            itemtype   => undef,
323
            itemtype   => undef,
472
            categorycode => undef,
324
            categorycode => undef,
473
            rules => {
325
            rules => {
474
                holdallowed => 1,
326
                holdallowed => 1,
475
                hold_fulfillment_policy => 'homebranch',
327
                hold_fulfillment_policy => 'holdgroup',
476
                returnbranch => 'any'
328
                returnbranch => 'any'
477
            }
329
            }
478
        }
330
        }
479
    );
331
    );
480
332
481
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
482
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
483
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
484
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
485
486
    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');
487
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
488
489
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
490
    Koha::CirculationRules->set_rules(
333
    Koha::CirculationRules->set_rules(
491
        {
334
        {
492
            branchcode => undef,
335
            branchcode => $library7->branchcode,
493
            itemtype   => undef,
336
            itemtype   => undef,
494
            categorycode => undef,
337
            categorycode => undef,
495
            rules => {
338
            rules => {
496
                holdallowed => 3,
339
                holdallowed => 3,
497
                hold_fulfillment_policy => 'homebranch',
498
                returnbranch => 'any'
499
            }
500
        }
501
    );
502
503
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
504
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
505
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
506
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
507
508
    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');
509
    ok(scalar(@pl_1_4) == 0, 'No pickup locations returned');
510
511
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
512
    Koha::CirculationRules->set_rules(
513
        {
514
            branchcode => undef,
515
            itemtype   => undef,
516
            categorycode => undef,
517
            rules => {
518
                holdallowed => 2,
519
                hold_fulfillment_policy => 'holdingbranch',
340
                hold_fulfillment_policy => 'holdingbranch',
520
                returnbranch => 'any'
341
                returnbranch => 'any'
521
            }
342
            }
522
        }
343
        }
523
    );
344
    );
524
345
525
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
526
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
527
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
528
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
529
530
    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');
531
346
532
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
533
    Koha::CirculationRules->set_rules(
347
    Koha::CirculationRules->set_rules(
534
        {
348
        {
535
            branchcode => undef,
349
            branchcode => $library8->branchcode,
536
            itemtype   => undef,
350
            itemtype   => undef,
537
            categorycode => undef,
351
            categorycode => undef,
538
            rules => {
352
            rules => {
539
                holdallowed => 1,
353
                holdallowed => 2,
540
                hold_fulfillment_policy => 'holdingbranch',
354
                hold_fulfillment_policy => 'patrongroup',
541
                returnbranch => 'any'
355
                returnbranch => 'any'
542
            }
356
            }
543
        }
357
        }
544
    );
358
    );
545
359
546
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
360
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
547
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
361
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
548
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
549
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
550
362
551
    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');
363
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
552
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
364
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
553
365
554
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
366
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
555
    Koha::CirculationRules->set_rules(
367
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
556
        {
368
    my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } );
557
            branchcode => undef,
369
    my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } );
558
            itemtype   => undef,
559
            categorycode => undef,
560
            rules => {
561
                holdallowed => 3,
562
                hold_fulfillment_policy => 'holdingbranch',
563
                returnbranch => 'any'
564
            }
565
        }
566
    );
567
370
568
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
371
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios', value => {title => '1'} } );
569
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
372
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
570
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
373
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios', value => {title => '2'} } );
571
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
374
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
572
375
573
    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');
376
    my $item1_1  = Koha::Item->new({
377
        biblionumber     => $biblio1->biblionumber,
378
        biblioitemnumber => $biblioitem1->biblioitemnumber,
379
        homebranch       => $library1->branchcode,
380
        holdingbranch    => $library2->branchcode,
381
        itype            => 'test',
382
        barcode          => "item11barcode",
383
    })->store;
574
384
575
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
385
    my $item1_3  = Koha::Item->new({
386
        biblionumber     => $biblio1->biblionumber,
387
        biblioitemnumber => $biblioitem1->biblioitemnumber,
388
        homebranch       => $library3->branchcode,
389
        holdingbranch    => $library4->branchcode,
390
        itype            => 'test',
391
        barcode          => "item13barcode",
392
    })->store;
576
393
577
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
394
    my $item1_7  = Koha::Item->new({
578
    Koha::CirculationRules->set_rules(
395
        biblionumber     => $biblio1->biblionumber,
579
        {
396
        biblioitemnumber => $biblioitem1->biblioitemnumber,
580
            branchcode => undef,
397
        homebranch       => $library7->branchcode,
581
            itemtype   => undef,
398
        holdingbranch    => $library4->branchcode,
582
            categorycode => undef,
399
        itype            => 'test',
583
            rules => {
400
        barcode          => "item17barcode",
584
                holdallowed => 1,
401
    })->store;
585
                hold_fulfillment_policy => 'any',
586
                returnbranch => 'any'
587
            }
588
        }
589
    );
590
402
591
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
403
    my $item2_2  = Koha::Item->new({
592
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
404
        biblionumber     => $biblio2->biblionumber,
593
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
405
        biblioitemnumber => $biblioitem2->biblioitemnumber,
594
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
406
        homebranch       => $library2->branchcode,
407
        holdingbranch    => $library1->branchcode,
408
        itype            => 'test',
409
        barcode          => "item22barcode",
410
    })->store;
595
411
596
    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');
412
    my $item2_4  = Koha::Item->new({
597
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
413
        biblionumber     => $biblio2->biblionumber,
414
        biblioitemnumber => $biblioitem2->biblioitemnumber,
415
        homebranch       => $library4->branchcode,
416
        holdingbranch    => $library3->branchcode,
417
        itype            => 'test',
418
        barcode          => "item23barcode",
419
    })->store;
598
420
599
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
421
    my $item2_6  = Koha::Item->new({
600
    Koha::CirculationRules->set_rules(
422
        biblionumber     => $biblio2->biblionumber,
601
        {
423
        biblioitemnumber => $biblioitem2->biblioitemnumber,
602
            branchcode => undef,
424
        homebranch       => $library6->branchcode,
603
            itemtype   => undef,
425
        holdingbranch    => $library4->branchcode,
604
            categorycode => undef,
426
        itype            => 'test',
605
            rules => {
427
        barcode          => "item26barcode",
606
                holdallowed => 1,
428
    })->store;
607
                hold_fulfillment_policy => 'holdgroup',
608
                returnbranch => 'any'
609
            }
610
        }
611
    );
612
429
613
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
430
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } );
614
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
431
    my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
615
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
616
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
617
432
618
    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');
433
    my $results = {
619
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
434
        "ItemHomeLibrary-1-1" => 6,
435
        "ItemHomeLibrary-1-8" => 1,
436
        "ItemHomeLibrary-2-1" => 2,
437
        "ItemHomeLibrary-2-8" => 0,
438
        "PatronLibrary-1-1" => 6,
439
        "PatronLibrary-1-8" => 3,
440
        "PatronLibrary-2-1" => 0,
441
        "PatronLibrary-2-8" => 3,
442
    };
620
443
621
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
444
    sub _doTest {
622
    Koha::CirculationRules->set_rules(
445
        my ( $cbranch, $biblio, $patron, $results ) = @_;
623
        {
446
        t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
624
            branchcode => undef,
625
            itemtype   => undef,
626
            categorycode => undef,
627
            rules => {
628
                holdallowed => 1,
629
                hold_fulfillment_policy => 'homebranch',
630
                returnbranch => 'any'
631
            }
632
        }
633
    );
634
447
635
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
448
        my @pl = $biblio->pickup_locations( { patron => $patron} );
636
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
637
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
638
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
639
449
640
    #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');
450
        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));
641
    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');
451
    }
642
    ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned');
643
452
644
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
453
    foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') {
645
    Koha::CirculationRules->set_rules(
454
        foreach my $biblio ($biblio1, $biblio2) {
646
        {
455
            foreach my $patron ($patron1, $patron8) {
647
            branchcode => undef,
456
                _doTest($cbranch, $biblio, $patron, $results);
648
            itemtype   => undef,
649
            categorycode => undef,
650
            rules => {
651
                holdallowed => 1,
652
                hold_fulfillment_policy => 'holdingbranch',
653
                returnbranch => 'any'
654
            }
457
            }
655
        }
458
        }
656
    );
459
    }
657
658
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
659
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
660
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
661
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
662
663
    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');
664
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
665
460
666
    $schema->storage->txn_rollback;
461
    $schema->storage->txn_rollback;
667
};
462
};
(-)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 179-185 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
179
$schema->storage->txn_rollback;
179
$schema->storage->txn_rollback;
180
180
181
subtest 'pickup_locations' => sub {
181
subtest 'pickup_locations' => sub {
182
    plan tests => 33;
182
    plan tests => 60;
183
183
184
    $schema->storage->txn_begin;
184
    $schema->storage->txn_begin;
185
185
Lines 219-226 subtest 'pickup_locations' => sub { Link Here
219
        biblioitemnumber => $biblioitem->{biblioitemnumber},
219
        biblioitemnumber => $biblioitem->{biblioitemnumber},
220
        homebranch       => $library1->branchcode,
220
        homebranch       => $library1->branchcode,
221
        holdingbranch    => $library2->branchcode,
221
        holdingbranch    => $library2->branchcode,
222
        barcode          => '1',
222
        itype            => 'test',
223
        itype            => 'test',
223
        barcode          => "item1barcode",
224
    })->store;
224
    })->store;
225
225
226
    my $item3  = Koha::Item->new({
226
    my $item3  = Koha::Item->new({
Lines 228-598 subtest 'pickup_locations' => sub { Link Here
228
        biblioitemnumber => $biblioitem->{biblioitemnumber},
228
        biblioitemnumber => $biblioitem->{biblioitemnumber},
229
        homebranch       => $library3->branchcode,
229
        homebranch       => $library3->branchcode,
230
        holdingbranch    => $library4->branchcode,
230
        holdingbranch    => $library4->branchcode,
231
        barcode          => '3',
231
        itype            => 'test',
232
        itype            => 'test',
232
        barcode          => "item3barcode",
233
    })->store;
233
    })->store;
234
234
235
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
235
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
236
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
236
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
237
237
238
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
238
    my $results = {
239
239
        "1-1-1-any" => 3,
240
    #Case 1: holdallowed any, hold_fulfillment_policy any
240
        "1-1-1-holdgroup" => 2,
241
    Koha::CirculationRules->set_rules(
241
        "1-1-1-patrongroup" => 2,
242
        {
242
        "1-1-1-homebranch" => 1,
243
            branchcode => undef,
243
        "1-1-1-holdingbranch" => 1,
244
            itemtype   => undef,
244
        "1-1-2-any" => 3,
245
            categorycode => undef,
245
        "1-1-2-holdgroup" => 2,
246
            rules => {
246
        "1-1-2-patrongroup" => 2,
247
                holdallowed => 2,
247
        "1-1-2-homebranch" => 1,
248
                hold_fulfillment_policy => 'any',
248
        "1-1-2-holdingbranch" => 1,
249
                returnbranch => 'any'
249
        "1-1-3-any" => 3,
250
        "1-1-3-holdgroup" => 2,
251
        "1-1-3-patrongroup" => 2,
252
        "1-1-3-homebranch" => 1,
253
        "1-1-3-holdingbranch" => 1,
254
        "1-4-1-any" => 0,
255
        "1-4-1-holdgroup" => 0,
256
        "1-4-1-patrongroup" => 0,
257
        "1-4-1-homebranch" => 0,
258
        "1-4-1-holdingbranch" => 0,
259
        "1-4-2-any" => 3,
260
        "1-4-2-holdgroup" => 2,
261
        "1-4-2-patrongroup" => 1,
262
        "1-4-2-homebranch" => 1,
263
        "1-4-2-holdingbranch" => 1,
264
        "1-4-3-any" => 0,
265
        "1-4-3-holdgroup" => 0,
266
        "1-4-3-patrongroup" => 0,
267
        "1-4-3-homebranch" => 0,
268
        "1-4-3-holdingbranch" => 0,
269
        "3-1-1-any" => 0,
270
        "3-1-1-holdgroup" => 0,
271
        "3-1-1-patrongroup" => 0,
272
        "3-1-1-homebranch" => 0,
273
        "3-1-1-holdingbranch" => 0,
274
        "3-1-2-any" => 3,
275
        "3-1-2-holdgroup" => 1,
276
        "3-1-2-patrongroup" => 2,
277
        "3-1-2-homebranch" => 0,
278
        "3-1-2-holdingbranch" => 1,
279
        "3-1-3-any" => 0,
280
        "3-1-3-holdgroup" => 0,
281
        "3-1-3-patrongroup" => 0,
282
        "3-1-3-homebranch" => 0,
283
        "3-1-3-holdingbranch" => 0,
284
        "3-4-1-any" => 0,
285
        "3-4-1-holdgroup" => 0,
286
        "3-4-1-patrongroup" => 0,
287
        "3-4-1-homebranch" => 0,
288
        "3-4-1-holdingbranch" => 0,
289
        "3-4-2-any" => 3,
290
        "3-4-2-holdgroup" => 1,
291
        "3-4-2-patrongroup" => 1,
292
        "3-4-2-homebranch" => 0,
293
        "3-4-2-holdingbranch" => 1,
294
        "3-4-3-any" => 3,
295
        "3-4-3-holdgroup" => 1,
296
        "3-4-3-patrongroup" => 1,
297
        "3-4-3-homebranch" => 0,
298
        "3-4-3-holdingbranch" => 1
299
    };
300
301
    sub _doTest {
302
        my ( $item, $patron, $ha, $hfp, $results ) = @_;
303
304
        Koha::CirculationRules->set_rules(
305
            {
306
                branchcode => undef,
307
                itemtype   => undef,
308
                categorycode => undef,
309
                rules => {
310
                    holdallowed => $ha,
311
                    hold_fulfillment_policy => $hfp,
312
                    returnbranch => 'any'
313
                }
250
            }
314
            }
251
        }
315
        );
252
    );
316
        my @pl = $item->pickup_locations( { patron => $patron} );
253
317
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
254
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
255
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
256
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
257
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
258
259
    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');
260
261
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
262
    Koha::CirculationRules->set_rules(
263
        {
264
            branchcode => undef,
265
            itemtype   => undef,
266
            categorycode => undef,
267
            rules => {
268
                holdallowed => 1,
269
                hold_fulfillment_policy => 'any',
270
                returnbranch => 'any'
271
            }
272
        }
273
    );
274
275
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
276
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
277
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
278
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
279
280
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
281
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
282
283
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
284
    Koha::CirculationRules->set_rules(
285
        {
286
            branchcode => undef,
287
            itemtype   => undef,
288
            categorycode => undef,
289
            rules => {
290
                holdallowed => 3,
291
                hold_fulfillment_policy => 'any',
292
                returnbranch => 'any'
293
            }
294
        }
295
    );
296
297
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
298
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
299
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
300
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
301
302
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
303
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
304
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
305
306
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
307
    Koha::CirculationRules->set_rules(
308
        {
309
            branchcode => undef,
310
            itemtype   => undef,
311
            categorycode => undef,
312
            rules => {
313
                holdallowed => 2,
314
                hold_fulfillment_policy => 'holdgroup',
315
                returnbranch => 'any'
316
            }
317
        }
318
    );
319
320
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
321
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
322
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
323
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
324
325
    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');
326
    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');
327
328
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
329
    Koha::CirculationRules->set_rules(
330
        {
331
            branchcode => undef,
332
            itemtype   => undef,
333
            categorycode => undef,
334
            rules => {
335
                holdallowed => 1,
336
                hold_fulfillment_policy => 'holdgroup',
337
                returnbranch => 'any'
338
            }
339
        }
340
    );
341
318
342
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
319
        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));
343
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
320
    }
344
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
345
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
346
347
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
348
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
349
350
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
351
    Koha::CirculationRules->set_rules(
352
        {
353
            branchcode => undef,
354
            itemtype   => undef,
355
            categorycode => undef,
356
            rules => {
357
                holdallowed => 3,
358
                hold_fulfillment_policy => 'holdgroup',
359
                returnbranch => 'any'
360
            }
361
        }
362
    );
363
321
364
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
365
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
366
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
367
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
368
369
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
370
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
371
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
372
373
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
374
    Koha::CirculationRules->set_rules(
375
        {
376
            branchcode => undef,
377
            itemtype   => undef,
378
            categorycode => undef,
379
            rules => {
380
                holdallowed => 2,
381
                hold_fulfillment_policy => 'homebranch',
382
                returnbranch => 'any'
383
            }
384
        }
385
    );
386
322
387
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
323
    foreach my $item ($item1, $item3) {
388
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
324
        foreach my $patron ($patron1, $patron4) {
389
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
325
            #holdallowed 1: homebranch, 2: any, 3: holdgroup
390
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
326
            foreach my $ha (1, 2, 3) {
391
327
                foreach my $hfp ('any', 'holdgroup', 'patrongroup', 'homebranch', 'holdingbranch') {
392
    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');
328
                    _doTest($item, $patron, $ha, $hfp, $results);
393
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
329
                }
394
395
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
396
    Koha::CirculationRules->set_rules(
397
        {
398
            branchcode => undef,
399
            itemtype   => undef,
400
            categorycode => undef,
401
            rules => {
402
                holdallowed => 1,
403
                hold_fulfillment_policy => 'homebranch',
404
                returnbranch => 'any'
405
            }
330
            }
406
        }
331
        }
407
    );
332
    }
408
409
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
410
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
411
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
412
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
413
414
    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');
415
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
416
417
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
418
    Koha::CirculationRules->set_rules(
419
        {
420
            branchcode => undef,
421
            itemtype   => undef,
422
            categorycode => undef,
423
            rules => {
424
                holdallowed => 3,
425
                hold_fulfillment_policy => 'homebranch',
426
                returnbranch => 'any'
427
            }
428
        }
429
    );
430
431
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
432
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
433
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
434
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
435
436
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
437
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
438
439
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
440
    Koha::CirculationRules->set_rules(
441
        {
442
            branchcode => undef,
443
            itemtype   => undef,
444
            categorycode => undef,
445
            rules => {
446
                holdallowed => 2,
447
                hold_fulfillment_policy => 'holdingbranch',
448
                returnbranch => 'any'
449
            }
450
        }
451
    );
452
453
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
454
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
455
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
456
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
457
458
    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');
459
    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');
460
461
462
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
463
    Koha::CirculationRules->set_rules(
464
        {
465
            branchcode => undef,
466
            itemtype   => undef,
467
            categorycode => undef,
468
            rules => {
469
                holdallowed => 1,
470
                hold_fulfillment_policy => 'holdingbranch',
471
                returnbranch => 'any'
472
            }
473
        }
474
    );
475
476
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
477
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
478
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
479
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
480
481
    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');
482
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
483
484
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
485
    Koha::CirculationRules->set_rules(
486
        {
487
            branchcode => undef,
488
            itemtype   => undef,
489
            categorycode => undef,
490
            rules => {
491
                holdallowed => 3,
492
                hold_fulfillment_policy => 'holdingbranch',
493
                returnbranch => 'any'
494
            }
495
        }
496
    );
497
498
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
499
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
500
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
501
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
502
503
    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');
504
    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');
505
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
506
507
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
508
509
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
510
    Koha::CirculationRules->set_rules(
511
        {
512
            branchcode => undef,
513
            itemtype   => undef,
514
            categorycode => undef,
515
            rules => {
516
                holdallowed => 1,
517
                hold_fulfillment_policy => 'any',
518
                returnbranch => 'any'
519
            }
520
        }
521
    );
522
523
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
524
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
525
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
526
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
527
528
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
529
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
530
531
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
532
    Koha::CirculationRules->set_rules(
533
        {
534
            branchcode => undef,
535
            itemtype   => undef,
536
            categorycode => undef,
537
            rules => {
538
                holdallowed => 1,
539
                hold_fulfillment_policy => 'holdgroup',
540
                returnbranch => 'any'
541
            }
542
        }
543
    );
544
545
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
546
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
547
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
548
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
549
550
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
551
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
552
553
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
554
    Koha::CirculationRules->set_rules(
555
        {
556
            branchcode => undef,
557
            itemtype   => undef,
558
            categorycode => undef,
559
            rules => {
560
                holdallowed => 1,
561
                hold_fulfillment_policy => 'homebranch',
562
                returnbranch => 'any'
563
            }
564
        }
565
    );
566
567
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
568
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
569
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
570
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
571
572
    #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');
573
    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');
574
575
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
576
    Koha::CirculationRules->set_rules(
577
        {
578
            branchcode => undef,
579
            itemtype   => undef,
580
            categorycode => undef,
581
            rules => {
582
                holdallowed => 1,
583
                hold_fulfillment_policy => 'holdingbranch',
584
                returnbranch => 'any'
585
            }
586
        }
587
    );
588
589
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
590
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
591
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
592
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
593
594
    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');
595
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
596
333
597
    $schema->storage->txn_rollback;
334
    $schema->storage->txn_rollback;
598
};
335
};
(-)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