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.
This commit is contained in:
14
disco.py
14
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 = (
|
||||
|
||||
Reference in New Issue
Block a user