From 46766d3ebc69fbc92f3cb8f3e3cd2fd054146368 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 18 Jan 2021 10:12:59 +1300 Subject: [PATCH] Bug 4037: Add item type filter to inventory tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds the ability to filter inventory by item type. Multiple item types can be selected at once. To test: 1) Apply patch and restart services. 2) Set up (at least) one item of a specific item type. 3) Go to Tools -> Inventory. 4) Scroll down to find the item types filter. Confirm the 'select all' and 'clear all' buttons work as expected. 5) Select a few item types, but DO NOT include the item type that you just set for your item. Confirm that your item does not show in the results. 6) Go back to the Inventory tool. This time submit a search that DOES include the item type you just set for your item. Confirm that your item does show in the results. 7) Confirm tests pass: prove t/db_dependent/Items/GetItemsForInventory.t Sponsored-by: Bibliotheksservice-Zentrum Baden-Württemberg (BSZ) --- C4/Items.pm | 12 +++++++-- .../prog/en/modules/tools/inventory.tt | 29 ++++++++++++++++++++++ t/db_dependent/Items/GetItemsForInventory.t | 7 +++++- tools/inventory.pl | 12 ++++++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 430ca8e477..10a5fb6e15 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -477,7 +477,6 @@ lists of authorized values for certain item fields. minlocation => $minlocation, maxlocation => $maxlocation, location => $location, - itemtype => $itemtype, ignoreissued => $ignoreissued, datelastseen => $datelastseen, branchcode => $branchcode, @@ -485,6 +484,7 @@ lists of authorized values for certain item fields. offset => $offset, size => $size, statushash => $statushash, + itemtypes => @itemsarray, } ); Retrieve a list of title/authors/barcode/callnumber, for biblio inventory. @@ -517,6 +517,7 @@ sub GetItemsForInventory { my $size = $parameters->{'size'} // ''; my $statushash = $parameters->{'statushash'} // ''; my $ignore_waiting_holds = $parameters->{'ignore_waiting_holds'} // ''; + my $items = $parameters->{'itemtypes'} // ''; my $dbh = C4::Context->dbh; my ( @bind_params, @where_strings ); @@ -576,7 +577,6 @@ sub GetItemsForInventory { push @where_strings, 'biblioitems.itemtype = ?'; push @bind_params, $itemtype; } - if ( $ignoreissued) { $query .= "LEFT JOIN issues ON items.itemnumber = issues.itemnumber "; push @where_strings, 'issues.date_due IS NULL'; @@ -587,6 +587,14 @@ sub GetItemsForInventory { push( @where_strings, q{(reserves.found != 'W' OR reserves.found IS NULL)} ); } + if ( $items and @{$items} > 0 ){ + my $joinedvals; + for my $itemtype (@{$items}){ + $joinedvals = join(',', @{$items}); + } + push @where_strings, "( biblioitems.itemtype IN (" . $joinedvals . ") OR items.itype IN (" . $joinedvals . ") )"; + } + if ( @where_strings ) { $query .= 'WHERE '; $query .= join ' AND ', @where_strings; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt index a6fe072d2d..d3409627bf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt @@ -157,7 +157,27 @@ +
  • + +
    +

    Select all | Clear all

    +
    + [% FOREACH itemtype IN itemtypes %] +
    + + +
    + [% IF loop.count() % 4 == 0 && !loop.last() %] +
    +
    + [% END %] + [% END %] +
    +
    +
  • + +
    @@ -432,6 +452,15 @@ $("fieldset#optionalfilters").hide(); } }); + + $("#checkallitemtypes").on("click",function(e){ + e.preventDefault(); + $(".branch_select").prop("checked",1); + }); + $("#checknoneitemtypes").on("click",function(e){ + e.preventDefault(); + $(".branch_select").prop("checked",0); + }); }); [% END %] diff --git a/t/db_dependent/Items/GetItemsForInventory.t b/t/db_dependent/Items/GetItemsForInventory.t index f7c221c87e..5e3ea7834c 100755 --- a/t/db_dependent/Items/GetItemsForInventory.t +++ b/t/db_dependent/Items/GetItemsForInventory.t @@ -46,7 +46,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'Skip items with waiting holds' => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; @@ -99,6 +99,11 @@ subtest 'Skip items with waiting holds' => sub { is( scalar @{$items_2}, $second_items_count, 'Results and count match' ); is( $first_items_count + 2, $second_items_count, 'Two items added, count makes sense' ); + my $real_itemtype_count = Koha::Items->search({ itype => $itemtype->itemtype })->count; + my $itype_str = "'" . $itemtype->itemtype . "'"; # manipulate string for db query + my ( $items_3, $itemtype_count ) = GetItemsForInventory({ itemtypes => [ $itype_str ] }); + is( $itemtype_count, $real_itemtype_count, 'Itemtype filter gets correct number of inventory items' ); + # Add 2 waiting holds C4::Reserves::AddReserve( { diff --git a/tools/inventory.pl b/tools/inventory.pl index 632968219d..e82e77fe99 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -126,6 +126,13 @@ for my $authvfield (@$statuses) { my @class_sources = Koha::ClassSources->search({ used => 1 }); my $pref_class = C4::Context->preference("DefaultClassificationSource"); +my @itemtypes = Koha::ItemTypes->search; +my @selected_itemtypes; +foreach my $itemtype ( @itemtypes ) { + if ( defined $input->param('itemtype-' . $itemtype->itemtype) ) { + push @selected_itemtypes, "'" . $itemtype->itemtype . "'"; + } +} $template->param( authorised_values => \@authorised_value_list, @@ -141,7 +148,8 @@ $template->param( uploadedbarcodesflag => ($uploadbarcodes || $barcodelist) ? 1 : 0, ignore_waiting_holds => $ignore_waiting_holds, class_sources => \@class_sources, - pref_class => $pref_class + pref_class => $pref_class, + itemtypes => \@itemtypes, ); # Walk through uploaded barcodes, report errors, mark as seen, check in @@ -251,6 +259,7 @@ if ( $op && ( !$uploadbarcodes || $compareinv2barcd )) { offset => 0, statushash => $staton, ignore_waiting_holds => $ignore_waiting_holds, + itemtypes => \@selected_itemtypes, }); } # Build rightplacelist used to check if a scanned item is in the right place. @@ -267,6 +276,7 @@ if( @scanned_items ) { offset => 0, statushash => undef, ignore_waiting_holds => $ignore_waiting_holds, + itemtypes => \@selected_itemtypes, }); # Convert the structure to a hash on barcode $rightplacelist = { -- 2.11.0