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
|
return dest
|
||||||
|
|
||||||
|
|
||||||
def generate_barcode(sku: str, dest_dir: Path) -> Path | None:
|
def generate_barcode(upc: str, dest_dir: Path) -> Path | None:
|
||||||
"""Generate a UPC-A barcode PNG from a SKU. Returns path to the .png file."""
|
"""Generate a UPC-A barcode PNG from a UPC number. Returns path to the .png file."""
|
||||||
digits = re.sub(r"\D", "", sku)
|
digits = re.sub(r"\D", "", upc)
|
||||||
if not digits:
|
if not digits:
|
||||||
return None
|
return None
|
||||||
# UPC-A needs exactly 11 digits (12th is check digit, auto-calculated)
|
# 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")
|
upc_cls = barcode.get_barcode_class("upca")
|
||||||
bc = upc_cls(digits, writer=ImageWriter())
|
bc = upc_cls(digits, writer=ImageWriter())
|
||||||
# barcode lib appends .png automatically
|
# barcode lib appends .png automatically
|
||||||
out = dest_dir / f"barcode_{sku}"
|
out = dest_dir / f"barcode_{upc}"
|
||||||
saved = bc.save(
|
saved = bc.save(
|
||||||
str(out),
|
str(out),
|
||||||
options={
|
options={
|
||||||
@@ -223,7 +223,7 @@ def generate_barcode(sku: str, dest_dir: Path) -> Path | None:
|
|||||||
)
|
)
|
||||||
return Path(saved)
|
return Path(saved)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" ⚠ Barcode generation failed for {sku}: {e}")
|
print(f" ⚠ Barcode generation failed for {upc}: {e}")
|
||||||
return None
|
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]
|
IMAGES_DIR / f"product_{i}_{sku}_placeholder.png", title[:30]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate barcode
|
# Generate barcode from UPC (not SKU)
|
||||||
bc_path = generate_barcode(sku, BARCODES_DIR)
|
bc_path = generate_barcode(upc, BARCODES_DIR)
|
||||||
|
|
||||||
# Escape LaTeX special characters in text fields
|
# Escape LaTeX special characters in text fields
|
||||||
safe_title = (
|
safe_title = (
|
||||||
|
|||||||
Reference in New Issue
Block a user