From 4b91ac5812b4a6452f07d3b85ac40637bc91f455 Mon Sep 17 00:00:00 2001 From: pi-bot-01 Date: Sat, 21 Mar 2026 23:16:42 -0700 Subject: [PATCH] Fix UPC barcode: use first 11 digits, not last 11 digits[-11:] was dropping the first digit of 12-digit UPCs. digits[:11] correctly passes the first 11 digits to the barcode library, which calculates the matching check digit. 728192558375 now encodes correctly (was 2819255837X before). --- disco.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/disco.py b/disco.py index 8f99f90..0ef0365 100644 --- a/disco.py +++ b/disco.py @@ -204,8 +204,9 @@ def generate_barcode(upc: str, dest_dir: Path) -> Path | None: digits = re.sub(r"\D", "", upc) if not digits: return None - # UPC-A needs exactly 11 digits (12th is check digit, auto-calculated) - digits = digits[-11:].zfill(11) + # UPC-A: pass first 11 digits, library auto-calculates the 12th (check digit) + # A full UPC is 12 digits where the 12th is already the check digit + digits = digits[:11].zfill(11) try: upc_cls = barcode.get_barcode_class("upca") bc = upc_cls(digits, writer=ImageWriter())