From 762b3acc86feca9351487977151aa437d5b757e8 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 --- C4/Items.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 3041d8f13e7..a91279b6654 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 ); @@ -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'}; } } -- 2.39.2