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

(-)a/Koha/Item.pm (-4 / +4 lines)
Lines 553-561 sub can_be_transferred { Link Here
553
553
554
}
554
}
555
555
556
=head3 _can_pickup_at
556
=head3 _can_pickup_locations
557
557
558
$item->_can_pickup_at({ to => $to_libraries, from => $from_library })
558
$item->_can_pickup_locations({ to => $to_libraries, from => $from_library })
559
Checks if an item can be transferred to given libraries.
559
Checks if an item can be transferred to given libraries.
560
560
561
This feature is controlled by two system preferences:
561
This feature is controlled by two system preferences:
Lines 577-583 If checking only one library please use $item->can_be_transferred. Link Here
577
577
578
=cut
578
=cut
579
579
580
sub _can_pickup_at {
580
sub _can_pickup_locations {
581
    my ($self, $params ) = @_;
581
    my ($self, $params ) = @_;
582
582
583
    my $to   = $params->{to};
583
    my $to   = $params->{to};
Lines 658-664 sub pickup_locations { Link Here
658
        })->as_list;
658
        })->as_list;
659
    }
659
    }
660
660
661
    my $pickup_locations = $self->_can_pickup_at({
661
    my $pickup_locations = $self->_can_pickup_locations({
662
        to => \@libs
662
        to => \@libs
663
    });
663
    });
664
664
(-)a/t/db_dependent/Koha/Item.t (-10 / +9 lines)
Lines 339-345 subtest 'pickup_locations' => sub { Link Here
339
    $schema->storage->txn_rollback;
339
    $schema->storage->txn_rollback;
340
};
340
};
341
341
342
subtest '_can_pickup_at' => sub {
342
subtest '_can_pickup_locations' => sub {
343
    plan tests =>8;
343
    plan tests =>8;
344
344
345
    $schema->storage->txn_begin;
345
    $schema->storage->txn_begin;
Lines 359-365 subtest '_can_pickup_at' => sub { Link Here
359
359
360
    my @to = ( $library1, $library2, $library3, $library4 );
360
    my @to = ( $library1, $library2, $library3, $library4 );
361
361
362
    my $pickup_locations = $item->_can_pickup_at({ to => \@to });
362
    my $pickup_locations = $item->_can_pickup_locations({ to => \@to });
363
    is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations");
363
    is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations");
364
364
365
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
365
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
Lines 372-378 subtest '_can_pickup_at' => sub { Link Here
372
        }
372
        }
373
    });
373
    });
374
374
375
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
375
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
376
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
376
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
377
377
378
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
378
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
Lines 383-393 subtest '_can_pickup_at' => sub { Link Here
383
        }
383
        }
384
    });
384
    });
385
385
386
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
386
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
387
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
387
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
388
388
389
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
389
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
390
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
390
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
391
    is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
391
    is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
392
392
393
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
393
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
Lines 398-404 subtest '_can_pickup_at' => sub { Link Here
398
        }
398
        }
399
    });
399
    });
400
400
401
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
401
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
402
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
402
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
403
403
404
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
404
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
Lines 409-424 subtest '_can_pickup_at' => sub { Link Here
409
        }
409
        }
410
    });
410
    });
411
411
412
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
412
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
413
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
413
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
414
414
415
415
416
    $pickup_locations = $item->_can_pickup_at({ to => \@to, from => $library2 });
416
    $pickup_locations = $item->_can_pickup_locations({ to => \@to, from => $library2 });
417
    is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations");
417
    is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations");
418
418
419
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
419
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
420
420
421
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
421
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
422
    is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations");
422
    is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations");
423
423
424
};
424
};
425
- 

Return to bug 26963