diff --git a/Koha/Items.pm b/Koha/Items.pm index 7e0a3e60f1..46df9675cd 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -678,17 +678,32 @@ sub search { if ( $status eq 'lost' ) { $self = $self->search( { itemlost => { '!=' => 0 } } ); } + if ( $status =~ '^lost-(.*)' ) { + $self = $self->search( { itemlost => $1 } ); + } if ( $status eq 'withdrawn' ) { $self = $self->search( { withdrawn => { '!=' => 0 } } ); } + if ( $status =~ '^withdrawn-(.*)' ) { + $self = $self->search( { withdrawn => $1 } ); + } if ( $status eq 'damaged' ) { $self = $self->search( { damaged => { '!=' => 0 } } ); } + if ( $status =~ '^damaged-(.*)' ) { + $self = $self->search( { damaged => $1 } ); + } if ( $status eq 'not_for_loan' ) { my @item_types_notforloan = Koha::ItemTypes->search( { notforloan => { '!=' => 0 } } )->get_column('itemtype'); $self = $self->search( [ { notforloan => { '!=' => 0 } }, { 'me.itype' => \@item_types_notforloan } ] ); } + if ( $status =~ '^not_for_loan-(.*)' ) { + my $av_not_for_loan = $1; + my @item_types_notforloan = + Koha::ItemTypes->search( { notforloan => $av_not_for_loan } )->get_column('itemtype'); + $self = $self->search( [ { notforloan => $av_not_for_loan }, { 'me.itype' => \@item_types_notforloan } ] ); + } if ( $status eq 'on_hold' ) { $self = $self->filter_by_has_holds; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc index 24479908df..081af1151c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc @@ -274,9 +274,13 @@ local_use: _("On-site checkout"), in_transit: _("In transit"), lost: _("Lost"), + ...Object.fromEntries([...av_lost].map(([k, v]) => [`lost-${k}`, `* ${v}`])), withdrawn: _("Withdrawn"), + ...Object.fromEntries([...av_withdrawn].map(([k, v]) => [`withdrawn-${k}`, `* ${v}`])), damaged: _("Damaged"), + ...Object.fromEntries([...av_damaged].map(([k, v]) => [`damaged-${k}`, `* ${v}`])), not_for_loan: _("Not for loan"), + ...Object.fromEntries([...av_not_for_loan].map(([k, v]) => [`not_for_loan-${k}`, `* ${v}`])), on_hold: _("On hold"), recalled: _("Recalled"), available: _("Available"), diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index a5bcd22a75..493adb9104 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -75,7 +75,7 @@ is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should subtest 'search' => sub { - plan tests => 9; + plan tests => 15; $schema->storage->txn_begin; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -160,6 +160,75 @@ subtest 'search' => sub { is( $withdrawn_items->count, 1, "Filtered to 1 withdrawn item" ); is( $notforloan_items->count, 1, "Filtered to 1 notforloan item" ); + $item_6->notforloan(-1)->store; + is_deeply( + [ + Koha::Items->search( + { + _status => 'not_for_loan', + biblionumber => $biblio->biblionumber, + } + )->get_column('itemnumber') + ], + [ $item_6->itemnumber ] + ); + is_deeply( + [ + Koha::Items->search( + { + _status => 'not_for_loan-1', + biblionumber => $biblio->biblionumber, + } + )->get_column('itemnumber') + ], + [] + ); + is_deeply( + [ + Koha::Items->search( + { + _status => 'not_for_loan--1', + biblionumber => $biblio->biblionumber, + } + )->get_column('itemnumber') + ], + [ $item_6->itemnumber ] + ); + $item_6->notforloan(2)->store; + is_deeply( + [ + Koha::Items->search( + { + _status => 'not_for_loan', + biblionumber => $biblio->biblionumber, + } + )->get_column('itemnumber') + ], + [ $item_6->itemnumber ] + ); + is_deeply( + [ + Koha::Items->search( + { + _status => 'not_for_loan-1', + biblionumber => $biblio->biblionumber, + } + )->get_column('itemnumber') + ], + [] + ); + is_deeply( + [ + Koha::Items->search( + { + _status => 'not_for_loan-2', + biblionumber => $biblio->biblionumber, + } + )->get_column('itemnumber') + ], + [ $item_6->itemnumber ] + ); + C4::Circulation::AddIssue( $patron, $item_1->barcode ); my $checked_out_items = Koha::Items->search(