[BUG]: Audit Scanner Creates Duplicate Item Entries When Multiple Barcodes Map to the Same Item
When performing an audit using barcode scanning, the system incorrectly prevents saving when different barcodes correspond to the same catalog item (e.g., multiple UPCs for "Kids (Size 5)").
Many inventory items—especially diapers, wipes, hygiene products, and donor-sourced goods—legitimately have multiple barcodes due to different manufacturers, packaging revisions, or bulk/single packaging differences. The system should allow each barcode to have its own audit line entry while still permitting the audit to be saved.
Currently, the audit validation blocks saving due to "duplicate item" conflicts, preventing users from completing audits that include items with multiple barcodes.
Current Behavior
-
Each barcode creates a separate audit row. (correct)
-
System warns that the item is a duplicate.
-
The user cannot save audit progress, blocking completion of the audit.
Summary of the Problem The barcode scanning flow works like this:
Scan barcode → JavaScript calls /barcode_items/find.json
Lookup returns → {item_id: 123, quantity: 50}
Form populated → Sets item_id=123 in dropdown, quantity=50
Multiple scans → Different barcodes for same item → Multiple line items with item_id=123
Save attempt → line_items_unique_by_item_id validation fails → "duplicate item" error
Expected Behavior
-
Each barcode creates a separate audit row. (correct)
-
Each audit row should still display the barcode number so the user knows the difference between two rows of the same item
-
The audit should allow saving even when multiple barcodes map to the same item
-
Upon saving an audit that contains multiple barcodes for a single item, a warning modal should appear telling the user that multiple entires per item will be consolidated
-
Identical barcode scans should still consolidate (existing 3-scan package counting feature preserved)
-
We should still disallow duplicate item entries for non-barcode scanning (using the item dropdown)
Steps To Reproduce
Go to Inventory → Inventory Audit → New Audit.
Begin an audit using the scanner (or just type in manually as if you were using a scanner).
Scan an item that has multiple barcodes mapped to the same item (Example: “Kids (Size 5)” diapers from different manufacturers).
Observe that the system creates multiple audit entry lines, one per barcode.
Attempt to save the audit or confirm the audit.
The system displays an error indicating the item is a duplicate, and saving is blocked. You have entered at least one duplicate item: Kids (Size 4)
Code of Conduct
- [x] I've read the Code of Conduct and understand my responsibilities as a member of the Ruby for Good community