From c6a2887254e8f8b35ada93f035cbfffbd8ab9bc1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 22 Oct 2019 11:36:28 +0200 Subject: [PATCH] Bug 23851: Add the homebranch prefix to the barcode when adding multiple copies of an items See the comment in the code for more information. Test plan: - Set autoBarcode to hbyymmincr - Create an item and click on the barcode field - A barcode prefixed by the homebranch is generated - Click the "Add multiple copies of this item" and enter 4 - Save => Without this patch only the first item has the homebranch prefix => With this patch applied they all have a barcode in the same format --- cataloguing/additem.pl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 52a8ca13a9..2c371def28 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -577,7 +577,17 @@ if ($op eq "additem") { # Putting it into the record if ($barcodevalue) { - $record->field($tagfield)->update($tagsubfield => $barcodevalue); + if ( C4::Context->preference("autoBarcode") eq 'hbyymmincr' && $i > 0 ) { # The first copy already contains the homebranch prefix + # This is terribly hacky but the easiest way to fix the way hbyymmincr is working + # Contrary to what one might think, the barcode plugin does not prefix the returned string with the homebranch + # For a single item, it is handled with some JS code (see cataloguing/value_builder/barcode.pl) + # But when adding multiple copies we need to prefix it here, + # so we retrieve the homebranch from the item and prefix the barcode with it. + my ($hb_field, $hb_subfield) = GetMarcFromKohaField( "items.homebranch" ); + my $homebranch = $record->subfield($hb_field, $hb_subfield); + $barcodevalue = $homebranch . $barcodevalue; + } + $record->field($tagfield)->update($tagsubfield => $barcodevalue); } # Checking if the barcode already exists -- 2.11.0