From b3f932f30b7d4ed3ed5a52adf0c26c3ca4b66033 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Sun, 10 May 2026 22:27:34 +0100 Subject: [PATCH] Register barcode in Grocy after creating product via "Create Product" 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. --- incl/processing.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/incl/processing.inc.php b/incl/processing.inc.php index 393e174..4d40a1c 100755 --- a/incl/processing.inc.php +++ b/incl/processing.inc.php @@ -329,6 +329,9 @@ function processRefreshedBarcode(string $barcode): void { $productInfo = API::getLastCreatedProduct(5); if ($productInfo != null) { DatabaseConnection::getInstance()->updateSavedBarcodeMatch($barcode, $productInfo->id); + API::addBarcode($productInfo->id, $barcode, null); + $log = new LogOutput("Associated barcode $barcode with " . $productInfo->name, EVENT_TYPE_ASSOCIATE_PRODUCT); + $log->setVerbose()->dontSendWebsocket()->createLog(); } }