From b5d54649af305f35ab7dab8d7720e938aed4824c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 19 Feb 2018 11:29:04 +0100 Subject: [PATCH] Bug 20206: Find barcodes with more or less leading zeroes Content-Type: text/plain; charset=utf-8 Test plan: Pick an item, change barcode to e.g. 0123456 Create a barcode file with 123456. Run inventory with it. Should be found and modified. Change barcode file by modifying 123456 to 00123456. Same result. Change barcode of another item to 000123456. Run inventory again on same barcode file: 0 modified, warn on duplicates? Signed-off-by: Marcel de Rooy --- koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt | 1 + tools/inventory.pl | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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 2db78af6bd..c580452ee4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt @@ -31,6 +31,7 @@
[% error.barcode | html %] [% IF (error.ERR_BARCODE) %]: barcode not found[% END %] + [% IF (error.ERR_DUPLICATE_BARCODES) %]: duplicate barcodes with leading zeroes[% END %] [% IF (error.ERR_WTHDRAWN) %]: item withdrawn[% END %] [% IF (error.ERR_ONLOAN_RET) %]: item was on loan. It was returned before marked as seen[% END %] [% IF (error.ERR_ONLOAN_NOT_RET) %]: item was on loan. couldn't be returned.[% END %] diff --git a/tools/inventory.pl b/tools/inventory.pl index 13b7a538a5..a4ecb87589 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -197,8 +197,11 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) { push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; } else { - my $item = Koha::Items->find({barcode => $barcode}); - if ( $item ) { + my $barcode_nz = $barcode; + $barcode_nz =~ s/^0*//; + my $item_rs = Koha::Items->search({barcode => { 'regexp', "^0*${barcode_nz}\$" }}); + if ( $item_rs->count == 1 ) { + my $item = $item_rs->next; # Modify date last seen for scanned items, remove lost status $item->set({ itemlost => 0, datelastseen => $date })->store; my $item_unblessed = $item->unblessed; @@ -217,6 +220,8 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { } } push @scanned_items, $item_unblessed; + } elsif( $item_rs->count > 1 ) { # duplicates like 1 and 01 + push @errorloop, { barcode => $barcode_nz, ERR_DUPLICATE_BARCODES => 1 }; } else { push @errorloop, { barcode => $barcode, ERR_BARCODE => 1 }; } -- 2.11.0