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

(-)a/Koha/Items.pm (-4 / +26 lines)
Lines 61-75 placing a hold on one of those items. Link Here
61
sub filter_by_for_hold {
61
sub filter_by_for_hold {
62
    my ($self) = @_;
62
    my ($self) = @_;
63
63
64
    my @hold_not_allowed_itypes = Koha::CirculationRules->search(
64
    my $default_rule = Koha::CirculationRules->get_effective_rule(
65
        {
65
        {
66
            rule_name    => 'holdallowed',
66
            rule_name    => 'holdallowed',
67
            branchcode   => undef,
68
            categorycode => undef,
69
            rule_value   => 'not_allowed',
67
            rule_value   => 'not_allowed',
70
        }
68
        }
71
    )->get_column('itemtype');
69
    );
70
    my @hold_not_allowed_itypes;
71
    if ( $default_rule ) {
72
        @hold_not_allowed_itypes = Koha::ItemTypes->search->get_column('itemtype');
73
        my @hold_allowed_itypes = Koha::CirculationRules->search(
74
            {
75
                rule_name    => 'holdallowed',
76
                rule_value   => { '!=' => 'not_allowed' },
77
                branchcode   => undef,
78
                categorycode => undef,
79
            }
80
        )->get_column('itemtype');
81
        @hold_not_allowed_itypes = array_minus( @hold_not_allowed_itypes, @hold_allowed_itypes )
82
    } else {
83
        @hold_not_allowed_itypes = Koha::CirculationRules->search(
84
            {
85
                rule_name    => 'holdallowed',
86
                branchcode   => undef,
87
                categorycode => undef,
88
                rule_value   => 'not_allowed',
89
            }
90
        )->get_column('itemtype');
91
    }
92
72
    push @hold_not_allowed_itypes, Koha::ItemTypes->search({ notforloan => 1 })->get_column('itemtype');
93
    push @hold_not_allowed_itypes, Koha::ItemTypes->search({ notforloan => 1 })->get_column('itemtype');
94
    @hold_not_allowed_itypes = uniq @hold_not_allowed_itypes;
73
95
74
    my $params = {
96
    my $params = {
75
        itemlost   => 0,
97
        itemlost   => 0,
(-)a/t/db_dependent/Koha/Holds.t (+7 lines)
Lines 532-537 subtest 'Desks' => sub { Link Here
532
subtest 'get_items_that_can_fill' => sub {
532
subtest 'get_items_that_can_fill' => sub {
533
    plan tests => 6;
533
    plan tests => 6;
534
534
535
    Koha::CirculationRules->search(
536
        {
537
            rule_name    => 'holdallowed',
538
            rule_value   => 'not_allowed',
539
        }
540
    )->delete;
541
535
    my $biblio = $builder->build_sample_biblio;
542
    my $biblio = $builder->build_sample_biblio;
536
    my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); # For 1, 2, 3, 4
543
    my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); # For 1, 2, 3, 4
537
    my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' });
544
    my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' });
(-)a/t/db_dependent/Koha/Items.t (-1 / +74 lines)
Lines 1639-1644 subtest 'can_be_transferred' => sub { Link Here
1639
       'We get the same result also if we pass the from-library parameter.');
1639
       'We get the same result also if we pass the from-library parameter.');
1640
};
1640
};
1641
1641
1642
subtest 'filter_by_for_hold' => sub {
1643
    plan tests => 12;
1644
1645
    Koha::CirculationRules->search(
1646
        {
1647
            rule_name    => 'holdallowed',
1648
            rule_value   => 'not_allowed',
1649
        }
1650
    )->delete;
1651
1652
    my $biblio = $builder->build_sample_biblio;
1653
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' );
1654
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } );
1655
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' );
1656
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } );
1657
    is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' );
1658
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } );
1659
    is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' );
1660
1661
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0 } );
1662
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } );
1663
    is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' );
1664
1665
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0 } );
1666
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } );
1667
    is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' );
1668
1669
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } );
1670
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } );
1671
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0);
1672
    is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' );
1673
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1);
1674
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' );
1675
1676
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
1677
    my $not_holdable_itemtype = $itemtype->itemtype;
1678
    $builder->build_sample_item(
1679
        {
1680
            biblionumber => $biblio->biblionumber,
1681
            itype        => $not_holdable_itemtype,
1682
        }
1683
    );
1684
    Koha::CirculationRules->set_rule(
1685
        {
1686
            branchcode   => undef,
1687
            itemtype     => $not_holdable_itemtype,
1688
            rule_name    => 'holdallowed',
1689
            rule_value   => 'not_allowed',
1690
        }
1691
    );
1692
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - holdallowed=not_allowed' );
1693
1694
    # Remove rule, test notforloan on itemtype
1695
    Koha::CirculationRules->set_rule(
1696
        {
1697
            branchcode   => undef,
1698
            itemtype     => $not_holdable_itemtype,
1699
            rule_name    => 'holdallowed',
1700
            rule_value   => undef,
1701
        }
1702
    );
1703
    is( $biblio->items->filter_by_for_hold->count, 7, '7 items for hold - rule deleted' );
1704
    $itemtype->notforloan(1)->store;
1705
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - notforloan' );
1706
1707
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
1708
    $biblio->biblioitem->itemtype($not_holdable_itemtype)->store;
1709
    is( $biblio->items->filter_by_for_hold->count, 0, '0 item-level_itypes=0' );
1710
1711
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
1712
1713
    $biblio->delete;
1714
};
1715
1642
# Reset nb_of_items prior to testing delete
1716
# Reset nb_of_items prior to testing delete
1643
$nb_of_items = Koha::Items->search->count;
1717
$nb_of_items = Koha::Items->search->count;
1644
1718
1645
- 

Return to bug 29087