Skip to content

Register barcode in Grocy after creating product via "Create Product"#297

Open
pacso wants to merge 1 commit into
Forceu:masterfrom
pacso:register-barcode-after-create
Open

Register barcode in Grocy after creating product via "Create Product"#297
pacso wants to merge 1 commit into
Forceu:masterfrom
pacso:register-barcode-after-create

Conversation

@pacso
Copy link
Copy Markdown

@pacso pacso commented May 10, 2026

Summary

When the user clicks Create Product on an unknown barcode in BB, BB opens Grocy's new-product page in a new tab with the OpenFoodFacts-derived name prefilled. After the Grocy tab closes, BB's processRefreshedBarcode() updates the local Barcodes table to point the scanned barcode at the just-created Grocy product — but it never registers the barcode against the product in Grocy itself.

The barcode only ends up in Grocy if the user also clicks Add or Consume in BB, which routes through API::addBarcode(). Reasonable users expect "Create Product" to fully integrate the new product, including the barcode, in a single action.

This adds the API::addBarcode() call inside processRefreshedBarcode(), immediately after the local-match update, plus the corresponding EVENT_TYPE_ASSOCIATE_PRODUCT log entry to match the existing pattern in index.php.

Side note

Subsequent Add/Consume clicks for the same row will still call API::addBarcode() (now a duplicate). Grocy returns an error which API::processError() already swallows, so the inventory action proceeds; the only effect is a stray "Could not set Grocy barcode" log line and a slightly misleading "Associated barcode" log entry. A nice follow-up would be to guard the index.php addBarcode call with a known-barcode check, but I've kept this PR focused on the user-facing bug.

Test plan

  • Scan an unknown barcode in BB
  • Click Create Product → Grocy opens → create the product → close tab
  • Confirm Grocy product master data now shows the barcode (previously empty)
  • Confirm BB log shows "Associated barcode X with " entry
  • Verify behaviour when no product is created within the 5s window (existing condition $productInfo != null should preserve the current behaviour)

When the user clicks "Create Product" on an unknown barcode, BB opens
Grocy's new-product page (with the OFF name prefilled) in a new tab.
After Grocy's tab closes, processRefreshedBarcode() updates BB's local
Barcodes table with the new product id, but it does not register the
barcode itself in Grocy. The barcode only got written to Grocy if the
user then clicked Add or Consume, which calls API::addBarcode().

Users reasonably expect "Create Product" to fully integrate the
product, including the barcode. This adds an API::addBarcode() call
in processRefreshedBarcode so the barcode is registered immediately,
and emits the corresponding EVENT_TYPE_ASSOCIATE_PRODUCT log entry.

Subsequent Add/Consume clicks will still call API::addBarcode (now a
duplicate); Grocy returns an error which is already swallowed by
processError, so the inventory action proceeds. A future change could
guard the addBarcode call in index.php with a known-barcode check.
pacso added a commit to pacso/barcodebuddy-docker that referenced this pull request May 10, 2026
Adds a patches/ directory and a Dockerfile step that applies each
*.patch against /app/bbuddy with --forward --silent, so patches that
have already been merged upstream become a no-op rather than a build
failure.

First patch (register-barcode-after-create.patch) is the one open as
Forceu/barcodebuddy#297 — it makes processRefreshedBarcode register
the barcode in Grocy after the user creates a product via BB's
"Create Product" flow, instead of leaving it for a follow-up
Add/Consume click.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant