From 7457089e27f56050b6c38720d4886a67b08d7166 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Wed, 31 Jul 2024 12:01:54 +0200 Subject: [PATCH] Bug 8425: Increment the barcode on each call of set_barcode() Duplicate barcodes are generated when placing an Order in Acquisitions when AcqCreateItem = "placing an order" and Autobarcode is turned on. The problem is that you can accidentally attach 3 items to an order, but only 1 will be saved to the database. When you go to receive your order, you can only receive 1 item as the other two were never made, since the barcode wasn't unique. In 3.8.0, a software error comes up which prevent any item creation, I believe, but master (3.9.x) doesn't throw any warnings or errors. Yes.. This tries and solve a bug from 3.8.0 /o/ Test plan: 1 - set syspref "autoBarcode" to generated in the form yymm001 2 - set the barcode field to "barcode.pl" in marc structure 3 - create a new basket 4 - add one item to this basket 5 - click on the barcode field -> it should have a barcode 6 - click on add item and click on the new barcode fiels, it should have the same value APPLY PATCH: 7 - click on the barcode field -> it should have a barcode 8 - click on add item and click on the new barcode fields, it should have an higher barcode. Note : The barcode is incremented each time the barcode with an empty value is clicked on and only on "hbyymmincr" mode. Therefore, if the librarian removes the value from barcode and click again, they could get another barcode. I do not know if it is an issue. Signed-off-by: Sam Sowanick --- cataloguing/value_builder/barcode.pl | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/cataloguing/value_builder/barcode.pl b/cataloguing/value_builder/barcode.pl index 5ec7dbece4..f3b5bb38ba 100755 --- a/cataloguing/value_builder/barcode.pl +++ b/cataloguing/value_builder/barcode.pl @@ -90,23 +90,44 @@ my $builder = sub { # default js body (if not filled by hbyymmincr) $scr or $scr = < -function set_barcode(id, force) { +if(typeof autobarcodetype == 'undefined') { + var autobarcodetype = "$autoBarcodeType"; + var attempt = -1; +} + +function set_barcode(id, force, offset=0) { $scr } function Focus$function_name(event) { - set_barcode(event.data.id, false); + if (autobarcodetype == "hbyymmincr"){ + if (document.getElementById(event.data.id).value == ''){ + attempt += 1 + } + set_barcode(event.data.id, false, attempt); + } + else{ + set_barcode(event.data.id, false); + } return false; } function Click$function_name(event) { - set_barcode(event.data.id, true); + if (autobarcodetype == "hbyymmincr"){ + if (document.getElementById(event.data.id).value == ''){ + attempt += 1 + } + set_barcode(event.data.id, false, attempt); + } + else{ + set_barcode(event.data.id, false); + } return false; } -- 2.39.2