Files
inventree-stock-tool/test_barcode_analyze.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

87 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""
Analyze barcode structure
"""
test_barcode = "[)>06PSAM9019-ND1PJL-100-25-T30PSAM9019-NDK1K9530640910K1172401379D25291T34755734000711K14LCNQ1811ZPICK12Z268520113Z99999920Z00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
print("Barcode structure analysis:")
print(f"Total length: {len(test_barcode)}")
print()
# Look for patterns
import re
# Find all capital letters followed by content
pattern = r'([A-Z]+)([^A-Z]*)'
matches = re.findall(pattern, test_barcode)
print("Pattern matches (Letter + Content):")
for i, (letter, content) in enumerate(matches[:20]):
if content:
print(f" {letter}: '{content}'")
print("\n" + "="*70)
# Check if there are specific field markers
markers = ['30P', '1P', 'Q', 'K', 'D', 'T', 'Z', 'P']
for marker in markers:
if marker in test_barcode:
idx = test_barcode.find(marker)
print(f"Found '{marker}' at position {idx}: {test_barcode[idx:idx+20]}")
print("\n" + "="*70)
# Try to identify the structure
# [)>06 is ANSI MH10.8.2 format
if test_barcode.startswith('[)>06'):
print("This is ANSI MH10.8.2 barcode format")
print("Format: [)>06 + Format Identifier + GS + Data + RS + EOT")
# The data section should start after the format header
data_start = 5 # After [)>06
# Look for common field identifiers
print("\nSearching for field identifiers:")
# Common identifiers in ANSI format:
# P = Part Number
# 1P = Supplier Part Number
# 30P = Customer Part Number
# Q = Quantity
# K = Batch/Lot
# Try a different approach - look for explicit markers
text = test_barcode[5:] # Skip header
# Find 30P marker
if '30P' in text:
idx = text.index('30P')
after_30p = text[idx+3:]
# Extract until next capital letter or known marker
part_match = re.match(r'([A-Z0-9\-]+)', after_30p)
if part_match:
print(f" Part (30P): {part_match.group(1)}")
# Find 1P marker
if '1P' in text:
idx = text.index('1P')
after_1p = text[idx+2:]
part_match = re.match(r'([A-Z0-9\-]+)', after_1p)
if part_match:
print(f" Supplier Part (1P): {part_match.group(1)}")
# Find P (might be part number)
if test_barcode.startswith('[)>06P'):
after_p = test_barcode[6:]
part_match = re.match(r'([A-Z0-9\-]+)', after_p)
if part_match:
print(f" Part (P): {part_match.group(1)}")
# Find Q for quantity
if 'Q' in text:
# Look for Q followed by digits
q_matches = re.findall(r'Q(\d+)', text)
if q_matches:
print(f" Quantity (Q): {q_matches}")