#!/usr/bin/env python3 """ Test barcode parsing with real-world examples """ from stocktool.stock_tool_gui_v2 import parse_scan # Your actual barcode test_barcode = "[)>06PSAM9019-ND1PJL-100-25-T30PSAM9019-NDK1K9530640910K1172401379D25291T34755734000711K14LCNQ1811ZPICK12Z268520113Z99999920Z00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" print("Testing barcode parsing...") print(f"Raw barcode length: {len(test_barcode)}") print(f"Raw barcode: {test_barcode[:100]}...") print() # Parse it part_code, quantity = parse_scan(test_barcode) print("Parsed Results:") print(f" Part Code: {part_code}") print(f" Quantity: {quantity}") print() # Show the hex representation to see separators print("Checking for separators:") for i, char in enumerate(test_barcode): if char in ['\x1D', '\x1E']: print(f" Found separator at position {i}: \\x{ord(char):02X}") # Try to manually parse to see what's there print("\nManual analysis:") import re SEP_RE = re.compile(r'[\x1D\x1E]') fields = SEP_RE.split(test_barcode) print(f"Number of fields after split: {len(fields)}") for i, field in enumerate(fields[:10]): # Show first 10 fields print(f" Field {i}: '{field}'") if field.startswith('30P'): print(f" → Part code: {field[3:]}") elif field.lower().startswith('1p'): print(f" → Part code (1P): {field[2:]}") elif field.lower().startswith('q') and field[1:].isdigit(): print(f" → Quantity: {field[1:]}")