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

(-)a/Koha/Items.pm (-3 / +14 lines)
Lines 32-37 use Koha::SearchEngine::Indexer; Link Here
32
use Koha::Item::Attributes;
32
use Koha::Item::Attributes;
33
use Koha::Item;
33
use Koha::Item;
34
use Koha::CirculationRules;
34
use Koha::CirculationRules;
35
use Koha::ItemTypes;
35
36
36
use base qw(Koha::Objects);
37
use base qw(Koha::Objects);
37
38
Lines 200-213 Returns a new resultset, containing only those items that are allowed to be book Link Here
200
sub filter_by_bookable {
201
sub filter_by_bookable {
201
    my ($self) = @_;
202
    my ($self) = @_;
202
203
204
    my $bookable_itypes = [ Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype') ];
205
    my $child_itypes    = [
206
        Koha::ItemTypes->search(
207
            {
208
                bookable    => 0,
209
                parent_type => { -in => $bookable_itypes },
210
            }
211
        )->get_column('itemtype')
212
    ];
213
    my $all_bookable_itypes = [ @$bookable_itypes, @$child_itypes ];
214
203
    if ( !C4::Context->preference('item-level_itypes') ) {
215
    if ( !C4::Context->preference('item-level_itypes') ) {
204
        return $self->search(
216
        return $self->search(
205
            [
217
            [
206
                { bookable => 1 },
218
                { bookable => 1 },
207
                {
219
                {
208
                    bookable              => undef,
220
                    bookable              => undef,
209
                    'biblioitem.itemtype' =>
221
                    'biblioitem.itemtype' => { -in => $all_bookable_itypes }
210
                        { -in => [ Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype') ] }
211
                },
222
                },
212
            ],
223
            ],
213
            { join => 'biblioitem' }
224
            { join => 'biblioitem' }
Lines 219-225 sub filter_by_bookable { Link Here
219
            { bookable => 1 },
230
            { bookable => 1 },
220
            {
231
            {
221
                bookable => undef,
232
                bookable => undef,
222
                itype    => { -in => [ Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype') ] }
233
                itype    => { -in => $all_bookable_itypes }
223
            },
234
            },
224
        ]
235
        ]
225
    );
236
    );
(-)a/t/db_dependent/Koha/Items.t (-2 / +31 lines)
Lines 2540-2546 subtest 'filter_by_for_hold' => sub { Link Here
2540
};
2540
};
2541
2541
2542
subtest 'filter_by_bookable' => sub {
2542
subtest 'filter_by_bookable' => sub {
2543
    plan tests => 4;
2543
    plan tests => 7;
2544
2544
2545
    $schema->storage->txn_begin;
2545
    $schema->storage->txn_begin;
2546
2546
Lines 2584-2589 subtest 'filter_by_bookable' => sub { Link Here
2584
        "filter_by_bookable returns the correct number of items when not set at item level and using item level itemtypes"
2584
        "filter_by_bookable returns the correct number of items when not set at item level and using item level itemtypes"
2585
    );
2585
    );
2586
2586
2587
    note("Parent itemtype fallback tests for filter_by_bookable");
2588
2589
    my $parent_itype =
2590
        $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1, parent_type => undef } } );
2591
    my $child_itype = $builder->build_object(
2592
        { class => 'Koha::ItemTypes', value => { bookable => 0, parent_type => $parent_itype->itemtype } } );
2593
2594
    my $biblio2    = $builder->build_sample_biblio( { itemtype => $child_itype->itemtype } );
2595
    my $child_item = $builder->build_sample_item(
2596
        { biblionumber => $biblio2->biblionumber, itype => $child_itype->itemtype, bookable => undef } );
2597
2598
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
2599
    is(
2600
        $biblio2->items->filter_by_bookable->count, 1,
2601
        "filter_by_bookable includes child of bookable parent (item-level_itypes=1)"
2602
    );
2603
2604
    t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
2605
    is(
2606
        $biblio2->items->filter_by_bookable->count, 1,
2607
        "filter_by_bookable includes child of bookable parent (item-level_itypes=0)"
2608
    );
2609
2610
    $child_item->bookable(0)->store();
2611
    $child_item->discard_changes;
2612
    is(
2613
        $biblio2->items->filter_by_bookable->count, 0,
2614
        "filter_by_bookable excludes item with explicit bookable=0 even if parent is bookable"
2615
    );
2616
2587
    $schema->storage->txn_rollback;
2617
    $schema->storage->txn_rollback;
2588
};
2618
};
2589
2619
2590
- 

Return to bug 41917