From ecc026d07b4240a4c04edbc2ea0c2686f2529bd1 Mon Sep 17 00:00:00 2001 From: pi-bot-01 Date: Sat, 21 Mar 2026 23:11:38 -0700 Subject: [PATCH] Use UPC (not SKU) for barcode generation UPC-A barcodes should encode the Universal Product Code, not the internal store SKU. The UPCs are already 12-digit numbers that match the barcodes on the physical product packaging. --- disco.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/disco.py b/disco.py index 849c5c4..791d64b 100644 --- a/disco.py +++ b/disco.py @@ -199,9 +199,9 @@ def make_placeholder(dest: Path, text: str = "No Image") -> Path: return dest -def generate_barcode(sku: str, dest_dir: Path) -> Path | None: - """Generate a UPC-A barcode PNG from a SKU. Returns path to the .png file.""" - digits = re.sub(r"\D", "", sku) +def generate_barcode(upc: str, dest_dir: Path) -> Path | None: + """Generate a UPC-A barcode PNG from a UPC number. Returns path to the .png file.""" + digits = re.sub(r"\D", "", upc) if not digits: return None # UPC-A needs exactly 11 digits (12th is check digit, auto-calculated) @@ -210,7 +210,7 @@ def generate_barcode(sku: str, dest_dir: Path) -> Path | None: upc_cls = barcode.get_barcode_class("upca") bc = upc_cls(digits, writer=ImageWriter()) # barcode lib appends .png automatically - out = dest_dir / f"barcode_{sku}" + out = dest_dir / f"barcode_{upc}" saved = bc.save( str(out), options={ @@ -223,7 +223,7 @@ def generate_barcode(sku: str, dest_dir: Path) -> Path | None: ) return Path(saved) except Exception as e: - print(f" ⚠ Barcode generation failed for {sku}: {e}") + print(f" ⚠ Barcode generation failed for {upc}: {e}") return None # --------------------------------------------------------------------------- @@ -291,8 +291,8 @@ def generate_catalog_pdf(products: list[dict]) -> Path | None: IMAGES_DIR / f"product_{i}_{sku}_placeholder.png", title[:30] ) - # Generate barcode - bc_path = generate_barcode(sku, BARCODES_DIR) + # Generate barcode from UPC (not SKU) + bc_path = generate_barcode(upc, BARCODES_DIR) # Escape LaTeX special characters in text fields safe_title = (