From 4bd4fd76792edcf0c9eaa72148c90be1b3cfbb9c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 1 Aug 2024 18:01:25 +0000 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall --- C4/Items.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 129a36f650c..be5a650c965 100644 --- a/C4/Items.pm +++ b/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 ); @@ -493,11 +494,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'}; } } -- 2.39.2