Bug 8425 - Autobarcode generates duplicate barcodes with AcqCreateItems = on order
Summary: Autobarcode generates duplicate barcodes with AcqCreateItems = on order
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Bugs List
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-12 05:46 UTC by David Cook
Modified: 2022-05-11 19:53 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:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2012-07-12 05:46:07 UTC
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.
Comment 1 Katrin Fischer 2012-07-12 05:50:35 UTC
Hm, this should not happen, but maybe it will help to set the UniqueItemFields to barcode? In my tests it worked really nicely, but perhaps something changed.
Comment 2 David Cook 2012-07-12 06:10:06 UTC
(In reply to comment #1)
> Hm, this should not happen, but maybe it will help to set the
> UniqueItemFields to barcode? In my tests it worked really nicely, but
> perhaps something changed.

No luck. Setting "barcode" in UniqueItemFields makes no change.

When did you test it?
Comment 3 Katrin Fischer 2012-07-12 06:21:01 UTC
Hm, I think I signed off on the patch introducing it, so the bug history should tell.
Comment 4 David Cook 2012-07-12 06:39:22 UTC
(In reply to comment #3)
> Hm, I think I signed off on the patch introducing it, so the bug history
> should tell.

Which patch is that, Katrin?

---

Also, when I look at my standard install 3.8.0 or my dev install 3.8.0 branch, the clear button works in the item block. However, it doesn't work in 3.8.2 (maybe 3.8.1) or higher...

Also, in my standard 3.8.0 install, duplicate barcodes creates this error:

DBD::mysql::st execute failed: Duplicate entry '201180550469528' for key 'itembarcodeidx' at .../lib/C4/Items.pm line 2127.

While in my dev install 3.8.0 branch, a nice JS window pops up to say:

"Duplicate values detected. Please correct the errors and resubmit."

As mentioned before, in 3.8.2+, no error message is generated and only the first item is created.
Comment 5 David Cook 2012-07-12 06:45:01 UTC
(In reply to comment #4)
> (In reply to comment #3)
> 
> Also, when I look at my standard install 3.8.0 or my dev install 3.8.0
> branch, the clear button works in the item block. However, it doesn't work
> in 3.8.2 (maybe 3.8.1) or higher...
> 

Hmm. I was a bit hasty there. The clear button clears all the fields except date and barcode... although I'm not sure that's a good thing...
Comment 6 David Cook 2012-07-16 01:51:41 UTC
Still not sure why this one is happening...

The relevant code in neworderempty.tt looks identical. neworderempty.pl looks like it should be passing everything correctly to the template too. 

additems.js seems close enough, although check_uniqueness.pl is very different...but a quick test didn't show a difference. 

Even when I replace all these files with files from a version where the dupe check works, the JS still fails to pick up the duplication of the barcodes. 

I'll have to try git bisect again, but anyone have any ideas on this one? I figure the problem must be with additems.js and check_uniqueness.pl...
Comment 7 Katrin Fischer 2012-08-24 06:32:11 UTC
Hi David, I filed a separate bug for the problem with the clear link, it's bug 8683 now.
Comment 8 Katrin Fischer 2012-08-24 06:38:01 UTC
I can replicate the problem:

When using Autobarcode items created on order will all get the same(!) barcode. Additionally the check on saving the order fails, so you get no notice and only one item is created.

I think this is because Autobarcode checks for the next barcode in the database. We are creating more than one item at once, so there is a problem.

I am not sure if that part of the problem can be solved easily, but the form should warn on saving when duplicate barcodes are detected.

Settings:
UniqueItemFields: barcode
AcqCreateItem: placing an order
Autobarcode: 1, 2, 3...

Turning off Autobarcode (do not generate) didn't solve the problem. There is a javascript error that you can see when saving the order in Firebug. Filing another bug for the broken duplicate check.
Comment 9 Liz Rea 2012-12-12 03:06:29 UTC
oops sorry - wrong bug!
Comment 10 Galen Charlton 2013-08-14 21:32:19 UTC
I'm not able to reproduce the problem -- I suspect it was fixed by the patch for bug 8495.

David: could you check to see if you're still seeing this?
Comment 11 David Cook 2013-08-16 06:28:25 UTC
(In reply to Galen Charlton from comment #10)
> I'm not able to reproduce the problem -- I suspect it was fixed by the patch
> for bug 8495.
> 
> David: could you check to see if you're still seeing this?

Really? That's odd. Admittedly, I don't fully comprehend the black magic that is the AJAX item add form in Acquisitions but I'm still seeing this :/.

The first item you add will have a new barcode ($nextnum in comparison to the database). However, each new item you add to an order will have the exact same barcode as that one since they're all using the same database data, right? I don't see any checks against the barcode for items already in the order...

Steps to Reproduce:

1) Syspref "AcqCreateItem" to "placing an order"
2) Autobarcode to any of the options (although I do get a Javascript error for " generated in the form <branchcode>yymm0001.". So probably try the others for the time being...)
3) UniqueItemFields to "barcode"

4) Go to acquisitions > new basket 
5) Click on the "barcode" field for a new item, and add that item
6) Repeat step #5 and observe that they all have the same barcode
Comment 12 Jonathan Druart 2015-09-04 08:40:27 UTC
The problem is that the items are not inserted in the DB when you click on the "Add item" button. So the item form generated just after does not know an item is on the road.
Hopefully, there is now a check when you submit the complete order "Duplicate values detected. Please correct the errors and resubmit."
The form is not submitted, there are identical barcodes.

It seems quite tricky to fix this one.