Bug 29689 - Update to 21.11 broken auto-generated barcode in <branchcode>0001 option
Summary: Update to 21.11 broken auto-generated barcode in <branchcode>0001 option
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: unspecified
Hardware: All All
: P4 blocker (vote)
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords: rel_21_11_candidate
Depends on: 28445
Blocks:
  Show dependency treegraph
 
Reported: 2021-12-13 19:20 UTC by Henry
Modified: 2022-01-10 16:13 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00,21.11.02


Attachments
Error in Chrome console (65.97 KB, image/png)
2021-12-13 19:20 UTC, Henry
Details
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr (1.85 KB, patch)
2021-12-14 11:14 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr (1.90 KB, patch)
2021-12-14 16:40 UTC, David Nind
Details | Diff | Splinter Review
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr (5.93 KB, patch)
2021-12-20 10:21 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr (5.98 KB, patch)
2021-12-20 20:52 UTC, Hayley Pelham
Details | Diff | Splinter Review
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr (6.04 KB, patch)
2021-12-22 11:21 UTC, Nick Clemens
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Henry 2021-12-13 19:20:20 UTC
Created attachment 128480 [details]
Error in Chrome console

Hi! In version 21.05 the automatic barcode generator for manual addition of items worked. When upgrading to 21.11, it stopped working. The chrome debug shows the following message attached

To reproduce the error, clicking on the item "p - barcode" generates the error on the console, and does not show any expected results.

The autoBarcode option is set to "<branchcode>yymm0001" .

Other autoBarcode options work except "<branchcode>aamm0001" .
Comment 1 Jonathan Druart 2021-12-14 11:14:10 UTC
Created attachment 128490 [details] [review]
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr

The selector is not correct, we need to use .input_marceditor instead of
name="field_value".

Test plan:
Set autoBarcode=<branchcode>yymm0001
Catalogue a new item, click into the barcode input
Notice that without this patch you get a JS error in the console

Uncaught TypeError: form.field_value is undefined
    Focustag_952_subfield_p_878344
    Focustag_952_subfield_p_878344_handler
    jQuery 11
    BindEventstag_952_subfield_p_878344

With this patch applied the barcode is correctly generated.

QA Note: it would be way easier if all add item forms were using the new
methods, it could be:
  let loc = document.getElementsByName('items.homebranch')[0].value;
Yes, that's all!
Comment 2 Henry 2021-12-14 13:51:47 UTC
All works, thanks =D
Comment 3 Jonathan Druart 2021-12-14 14:14:42 UTC
This patch needs to be integrated. Can you signoff on the patch?

https://wiki.koha-community.org/wiki/Sign_off_on_patches
Comment 4 David Nind 2021-12-14 16:40:06 UTC
Created attachment 128521 [details] [review]
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr

The selector is not correct, we need to use .input_marceditor instead of
name="field_value".

Test plan:
Set autoBarcode=<branchcode>yymm0001
Catalogue a new item, click into the barcode input
Notice that without this patch you get a JS error in the console

Uncaught TypeError: form.field_value is undefined
    Focustag_952_subfield_p_878344
    Focustag_952_subfield_p_878344_handler
    jQuery 11
    BindEventstag_952_subfield_p_878344

With this patch applied the barcode is correctly generated.

QA Note: it would be way easier if all add item forms were using the new
methods, it could be:
  let loc = document.getElementsByName('items.homebranch')[0].value;
Yes, that's all!

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 Nick Clemens 2021-12-17 13:58:10 UTC
This works on additem.pl and neworderempty.pl but it fails on serials-edit.pl - I don't get the branchcode - though that page works before this patch
Comment 6 Manos PETRIDIS 2021-12-18 11:35:07 UTC
Same behaviour here, autoBarcode set to <branchcode>yymm0001 but barcodes are not auto-generated after upgrading to 21.11.
Comment 7 Jonathan Druart 2021-12-20 10:21:12 UTC
Created attachment 128727 [details] [review]
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr

The selector is not correct, we must to not rely on the number.
This patch fixes a regression caused by bug 28445, but also a
long-standing bug.

* Regression:
The barcode plugin is broken is autoBarcode=<branchcode>yymm0001
There is a JS error in the console:
  Uncaught TypeError: form.field_value is undefined
      Focustag_952_subfield_p_878344
      Focustag_952_subfield_p_878344_handler
      jQuery 11
      BindEventstag_952_subfield_p_878344

* Long standing bug:
If there are several item forms on the same page, the branchcode is not
correctly retrieved. For instance on the "Serial edition" page there are
2 item forms, the homebranch that is used by the barcode plugin will be
the one from the last form.

Test plan:
* regression
Set autoBarcode=<branchcode>yymm0001
Catalogue a new item, click into the barcode input
Notice that without this patch you get a JS error in the console

* long standing bug
Create a new subscription, select "Create an item record when receiving this serial".
Receive a serial
Open the 2 item forms ("Click to add item")
Select 2 different home library and click the barcode inputs.
The prefix (branchcode) should be correct with this patch applied.

QA Note: it would be way easier if all add item forms were using the new
methods, it could be:
  let loc = document.getElementsByName('items.homebranch')[0].value;
Yes, that's all!
Comment 8 Jonathan Druart 2021-12-20 10:21:53 UTC
(In reply to Nick Clemens from comment #5)
> This works on additem.pl and neworderempty.pl but it fails on
> serials-edit.pl - I don't get the branchcode - though that page works before
> this patch

Thanks Nick!
Comment 9 Jonathan Druart 2021-12-20 10:22:23 UTC
This patch needs quick attention if we want to have it part of 21.11.01
Comment 10 Hayley Pelham 2021-12-20 20:52:24 UTC
Created attachment 128800 [details] [review]
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr

The selector is not correct, we must to not rely on the number.
This patch fixes a regression caused by bug 28445, but also a
long-standing bug.

* Regression:
The barcode plugin is broken is autoBarcode=<branchcode>yymm0001
There is a JS error in the console:
  Uncaught TypeError: form.field_value is undefined
      Focustag_952_subfield_p_878344
      Focustag_952_subfield_p_878344_handler
      jQuery 11
      BindEventstag_952_subfield_p_878344

* Long standing bug:
If there are several item forms on the same page, the branchcode is not
correctly retrieved. For instance on the "Serial edition" page there are
2 item forms, the homebranch that is used by the barcode plugin will be
the one from the last form.

Test plan:
* regression
Set autoBarcode=<branchcode>yymm0001
Catalogue a new item, click into the barcode input
Notice that without this patch you get a JS error in the console

* long standing bug
Create a new subscription, select "Create an item record when receiving this serial".
Receive a serial
Open the 2 item forms ("Click to add item")
Select 2 different home library and click the barcode inputs.
The prefix (branchcode) should be correct with this patch applied.

QA Note: it would be way easier if all add item forms were using the new
methods, it could be:
  let loc = document.getElementsByName('items.homebranch')[0].value;
Yes, that's all!

Signed-off-by: Hayley Pelham <hayleypelham@catalyst.net.nz>
Comment 11 Nick Clemens 2021-12-22 11:21:45 UTC
Created attachment 128860 [details] [review]
Bug 29689: (bug 28445 follow-up) Fix AutoBarcode=hbyymmincr

The selector is not correct, we must to not rely on the number.
This patch fixes a regression caused by bug 28445, but also a
long-standing bug.

* Regression:
The barcode plugin is broken is autoBarcode=<branchcode>yymm0001
There is a JS error in the console:
  Uncaught TypeError: form.field_value is undefined
      Focustag_952_subfield_p_878344
      Focustag_952_subfield_p_878344_handler
      jQuery 11
      BindEventstag_952_subfield_p_878344

* Long standing bug:
If there are several item forms on the same page, the branchcode is not
correctly retrieved. For instance on the "Serial edition" page there are
2 item forms, the homebranch that is used by the barcode plugin will be
the one from the last form.

Test plan:
* regression
Set autoBarcode=<branchcode>yymm0001
Catalogue a new item, click into the barcode input
Notice that without this patch you get a JS error in the console

* long standing bug
Create a new subscription, select "Create an item record when receiving this serial".
Receive a serial
Open the 2 item forms ("Click to add item")
Select 2 different home library and click the barcode inputs.
The prefix (branchcode) should be correct with this patch applied.

QA Note: it would be way easier if all add item forms were using the new
methods, it could be:
  let loc = document.getElementsByName('items.homebranch')[0].value;
Yes, that's all!

Signed-off-by: Hayley Pelham <hayleypelham@catalyst.net.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 12 Fridolin Somers 2022-01-04 07:54:22 UTC
Pushed to master for 22.05, thanks to everybody involved 🦄
Comment 13 Manos PETRIDIS 2022-01-05 14:07:00 UTC
In my installation (single active branch/library, not a lending library, less than 9999 new items per month, autoBarcode set to <branchcode>yymm0001) I've used the following SQL statement to fill missing barcodes. Should you decide to use it, please remember to first check it thourougly and change "ABC" with your own branch code. I know it will leave gaps in the barcode sequence, but I don't really mind it.

UPDATE items
SET barcode = CONCAT (
		'ABC'
		,lpad(substring(extract(YEAR FROM datelastseen), 3, 2), 2, 0)
		,lpad(extract(month FROM datelastseen), 2, 0)
		,lpad(1 + itemnumber - (
				SELECT T.INI
				FROM (
					SELECT min(i.itemnumber) AS ini
						,extract(YEAR FROM i.datelastseen) AS DTE_YY
						,extract(month FROM i.datelastseen) AS DTE_MM
					FROM items i
					WHERE i.homebranch = 'ABC'
					GROUP BY extract(YEAR FROM i.datelastseen)
						,extract(month FROM i.datelastseen)
					) T
				WHERE T.dte_yy = extract(YEAR FROM datelastseen)
					AND T.DTE_MM = extract(MONTH FROM datelastseen)
				), 4, 0)
		)
WHERE items.homebranch = 'ABC'
	AND barcode IS NULL;
Comment 14 Manos PETRIDIS 2022-01-05 16:33:41 UTC
...oops, thoroughly!
Comment 15 Kyle M Hall 2022-01-07 11:20:36 UTC
Pushed to 21.11.x for 21.11.02
Comment 16 Andrew Fuerste-Henry 2022-01-10 16:13:48 UTC
Missing dependency, not backported to 21.05.x