Bug 37550: CheckItemPreSave should run barcodes through barcodedecode
In Koha::Item we run a barcode through barcodedecode before any save.
We should do the same when checking barcodes to avoid a duplicate error
when the barcode is cleaned before it is written to the DB
To test:
1 - Follow previous test plan
2 - Note that after this patch is applied there is no exception
All items are skipped as duplicate barcodes
Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit a262ffbdfa)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
ad83fffffd
commit
7d4399a99f
13
C4/Items.pm
13
C4/Items.pm
|
|
@ -45,6 +45,7 @@ BEGIN {
|
|||
}
|
||||
|
||||
use Carp qw( croak );
|
||||
use C4::Circulation qw( barcodedecode );
|
||||
use C4::Context;
|
||||
use C4::Koha;
|
||||
use C4::Biblio qw( GetMarcStructure TransformMarcToKoha );
|
||||
|
|
@ -459,11 +460,15 @@ sub CheckItemPreSave {
|
|||
my %errors = ();
|
||||
|
||||
# check for duplicate barcode
|
||||
if (exists $item_ref->{'barcode'} and defined $item_ref->{'barcode'}) {
|
||||
my $existing_item= Koha::Items->find({barcode => $item_ref->{'barcode'}});
|
||||
if ( exists $item_ref->{'barcode'} and defined $item_ref->{'barcode'} ) {
|
||||
my $barcode = C4::Circulation::barcodedecode( $item_ref->{'barcode'} );
|
||||
my $existing_item = Koha::Items->find( { barcode => $barcode } );
|
||||
if ($existing_item) {
|
||||
if (!exists $item_ref->{'itemnumber'} # new item
|
||||
or $item_ref->{'itemnumber'} != $existing_item->itemnumber) { # existing item
|
||||
if (
|
||||
!exists $item_ref->{'itemnumber'} # new item
|
||||
or $item_ref->{'itemnumber'} != $existing_item->itemnumber
|
||||
)
|
||||
{ # existing item
|
||||
$errors{'duplicate_barcode'} = $item_ref->{'barcode'};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue