From ff19e20314d0144f2b2c1d9e9ccfcf535a3cace6 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 4 Jan 2018 15:00:28 +0000 Subject: [PATCH] Bug 19915 - Use cn_sort values for getting inventory items To test: 1 - Catalog an item under LCC with callnumber GT95 2 - cn_sort should calculate as GT0095 3 - Go to inventory tool 4 - Enter a range that should have your item e.g LC GT90 to GT100 5 - Item is not returned 6 - Apply patch 7 - Item should be returned 8 - Verify things otherwise work as expected --- C4/Items.pm | 12 ++++++++---- koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt | 13 ++++++++++++- t/db_dependent/Items/GetItemsForInventory.t | 2 +- tools/inventory.pl | 10 ++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index a3ecd87..12c1b73 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -809,6 +809,7 @@ sub GetItemsForInventory { my ( $parameters ) = @_; my $minlocation = $parameters->{'minlocation'} // ''; my $maxlocation = $parameters->{'maxlocation'} // ''; + my $class_source = $parameters->{'class_source'} // C4::Context->preference('DefaultClassificationSource'); my $location = $parameters->{'location'} // ''; my $itemtype = $parameters->{'itemtype'} // ''; my $ignoreissued = $parameters->{'ignoreissued'} // ''; @@ -822,6 +823,9 @@ sub GetItemsForInventory { my $dbh = C4::Context->dbh; my ( @bind_params, @where_strings ); + my $min_cnsort = GetClassSort($class_source,undef,$minlocation); + my $max_cnsort = GetClassSort($class_source,undef,$maxlocation); + my $select_columns = q{ SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, withdrawn, stocknumber }; @@ -841,13 +845,13 @@ sub GetItemsForInventory { } if ($minlocation) { - push @where_strings, 'itemcallnumber >= ?'; - push @bind_params, $minlocation; + push @where_strings, 'items.cn_sort >= ?'; + push @bind_params, $min_cnsort; } if ($maxlocation) { - push @where_strings, 'itemcallnumber <= ?'; - push @bind_params, $maxlocation; + push @where_strings, 'items.cn_sort <= ?'; + push @bind_params, $max_cnsort; } if ($datelastseen) { 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 ed55ceb..f27ea97 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt @@ -79,7 +79,18 @@ (items.itemcallnumber)
  • -
  • +
  • + + +
  • diff --git a/t/db_dependent/Items/GetItemsForInventory.t b/t/db_dependent/Items/GetItemsForInventory.t index 40500ad..a09359a 100755 --- a/t/db_dependent/Items/GetItemsForInventory.t +++ b/t/db_dependent/Items/GetItemsForInventory.t @@ -79,7 +79,7 @@ subtest 'Use cn_sort rather than callnumber to determine correct location' => su minlocation => 'GT90', class_source => $class_source->{cn_source}, }); - is($item_count,1,"We should return GT95 as betwen GT90 and GT100"); + is($item_count,1,"We should return GT95 as between GT90 and GT100"); $schema->storage->txn_rollback; }; diff --git a/tools/inventory.pl b/tools/inventory.pl index c671488..6944f71 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -39,10 +39,12 @@ use Koha::Biblios; use Koha::DateUtils; use Koha::AuthorisedValues; use Koha::BiblioFrameworks; +use Koha::ClassSources; use List::MoreUtils qw( none ); my $minlocation=$input->param('minlocation') || ''; my $maxlocation=$input->param('maxlocation'); +my $class_source=$input->param('class_source'); $maxlocation=$minlocation.'Z' unless ( $maxlocation || ! $minlocation ); my $location=$input->param('location') || ''; my $ignoreissued=$input->param('ignoreissued'); @@ -114,6 +116,10 @@ for my $authvfield (@$statuses) { } } +my @class_sources = Koha::ClassSources->search(); +my $pref_class = C4::Context->preference("DefaultClassificationSource"); + + $template->param( authorised_values => \@authorised_value_list, today => dt_from_string, @@ -126,6 +132,8 @@ $template->param( datelastseen => $datelastseen, compareinv2barcd => $compareinv2barcd, uploadedbarcodesflag => $uploadbarcodes ? 1 : 0, + class_sources => \@class_sources, + pref_class => $pref_class ); # Walk through uploaded barcodes, report errors, mark as seen, check in @@ -222,6 +230,7 @@ if ( $op && ( !$uploadbarcodes || $compareinv2barcd )) { ( $inventorylist ) = GetItemsForInventory({ minlocation => $minlocation, maxlocation => $maxlocation, + class_source => $class_source, location => $location, ignoreissued => $ignoreissued, datelastseen => $datelastseen, @@ -236,6 +245,7 @@ if( @scanned_items ) { ( $rightplacelist ) = GetItemsForInventory({ minlocation => $minlocation, maxlocation => $maxlocation, + class_source => $class_source, location => $location, ignoreissued => undef, datelastseen => undef, -- 2.1.4