From f6a527261f33799bf444cbc050355362e6828d5c Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 13 Jan 2025 21:08:02 +0000 Subject: [PATCH] Bug 37334: Add ability to filter by in_bundle --- Koha/Item.pm | 4 +++- Koha/Items.pm | 21 +++++++++++++++++++ .../tables/items/catalogue_detail.inc | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index be6802a09d3..745b990d23e 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1484,7 +1484,9 @@ sub _status { push @statuses, 'restricted'; } - # TODO in_bundle? + if ( $self->in_bundle ) { + push @statuses, 'in_bundle'; + } return join ',', @statuses; } diff --git a/Koha/Items.pm b/Koha/Items.pm index 0677be9e31b..af85514e4b6 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -313,6 +313,24 @@ sub filter_by_has_recalls { return $self->search( { 'me.itemnumber' => { '-in' => $recalls } } ); } +=head3 filter_by_in_bundle + +Returns a new resultset, containing only those items that currently are part of a bundle. + +=cut + +sub filter_by_in_bundle { + my ($self) = @_; + + my @in_bundle_items; + while (my $item = $self->next) { + push @in_bundle_items, $item if $item->in_bundle; + } + + my @bundled_items = map { $_->itemnumber } @in_bundle_items; + return $self->search({ 'me.itemnumber' => { '-in' => \@bundled_items } }); +} + =head3 filter_by_available my $available_items = $items->filter_by_available; @@ -651,6 +669,9 @@ sub search { if ( $status eq 'recalled' ) { $self = $self->filter_by_has_recalls; } + if ( $status eq 'in_bundle' ) { + $self = $self->filter_by_in_bundle; + } if ( $status eq 'available' ) { $self = $self->filter_by_available; 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 ef021275ef1..6bd3c84ac47 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 @@ -216,7 +216,7 @@ }); const item_types_notforloan = new Map(all_item_types.map( it => [it.itemtype, it.notforloan] )); - const statuses = {checked_out: _("Checked out"), local_use: _("On-site checkout"), in_transit: _("In transit"), lost: _("Lost"), withdrawn: _("Withdrawn"), damaged:_("Damaged"), not_for_loan: _("Not for loan"), on_hold: _("On hold"), recalled: _("Recalled"), available: _("Available"), restricted: _("Restricted")}; + const statuses = {checked_out: _("Checked out"), local_use: _("On-site checkout"), in_transit: _("In transit"), lost: _("Lost"), withdrawn: _("Withdrawn"), damaged:_("Damaged"), not_for_loan: _("Not for loan"), on_hold: _("On hold"), recalled: _("Recalled"), available: _("Available"), restricted: _("Restricted"), in_bundle: _("In bundle")}; const all_statuses = Object.keys(statuses).map(k => {return {_id: k, _str: statuses[k]}}); const can_edit_items_from = [% To.json(can_edit_items_from || []) | $raw %]; -- 2.39.5