Files
inventree-stock-tool/test_barcode_parsing.py
grabowski 8dadd66f45 fix: Add support for ANSI MH10.8.2 barcode format
Fixes barcode parsing for ANSI MH10.8.2 format barcodes that don't use GS/RS separators.

Problem:
- Barcodes like [)>06PSAM9019-ND1PJL-100-25-T... were not being parsed
- Only separator-based and JSON formats were supported
- User's real-world barcodes were being added to queue as raw strings

Solution:
- Added ANSI MH10.8.2 format detection ([)>06 prefix)
- Extract part code between P and first field marker (1P, 30P)
- Extract quantity from Q<digits> pattern
- Updated both desktop and web app parsing logic

Tested with real barcode:
- Input: [)>06PSAM9019-ND1PJL-100-25-T30PSAM9019-NDK1...Q1811...
- Parsed: Part=SAM9019-ND, Qty=1811 

Files Changed:
- src/stocktool/stock_tool_gui_v2.py - Enhanced parse_scan()
- src/stocktool/web/static/js/app.js - Enhanced parseBarcode()
- test_barcode_parsing.py - Test script for validation
- test_barcode_analyze.py - Barcode structure analysis tool
- QUICKSTART_WEB.md - Quick start guide for web app

Supported Formats Now:
1. JSON-like: {PM:PART-CODE,QTY:10}
2. Separator-based: GS/RS (\x1D, \x1E) separated fields
3. ANSI MH10.8.2: [)>06P<part>...Q<qty>... (NEW!)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 11:29:20 +07:00

45 lines
1.5 KiB
Python

#!/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:]}")