fix: normalize non-standard GTIN lengths to EAN-13
- Pad non-standard lengths (9-12 digits) to EAN-13 (13 digits) - EAN-13 is the European/international standard - Handle .0 suffix from float conversion in import files - Change warnings to debug-level logging to reduce noise 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,24 +51,19 @@ class GTINProcessor:
|
||||
length = len(gtin_clean)
|
||||
|
||||
if length in self.VALID_LENGTHS:
|
||||
# Standard lengths - pad appropriately
|
||||
if length == 8:
|
||||
return gtin_clean.zfill(8) # EAN-8
|
||||
if length == 12:
|
||||
return gtin_clean.zfill(12) # UPC-A
|
||||
if length == 13:
|
||||
return gtin_clean.zfill(13) # EAN-13
|
||||
if length == 14:
|
||||
return gtin_clean.zfill(14) # GTIN-14
|
||||
# Standard lengths - return as-is (already valid)
|
||||
return gtin_clean
|
||||
|
||||
elif length > 14:
|
||||
# Too long - truncate to EAN-13
|
||||
logger.warning(f"GTIN too long, truncating: {gtin_clean}")
|
||||
logger.debug(f"GTIN too long ({length} digits), truncating: {gtin_clean}")
|
||||
return gtin_clean[-13:]
|
||||
|
||||
elif 0 < length < 8:
|
||||
# Too short - pad to EAN-13
|
||||
logger.warning(f"GTIN too short, padding: {gtin_clean}")
|
||||
elif 0 < length < 14:
|
||||
# Non-standard length - pad to EAN-13 (European standard)
|
||||
# EAN-13 is the international standard used in Europe and most of the world
|
||||
# UPC-A (12 digits) is primarily US/Canada
|
||||
logger.debug(f"GTIN non-standard ({length} digits), padding to EAN-13: {gtin_clean}")
|
||||
return gtin_clean.zfill(13)
|
||||
|
||||
logger.warning(f"Invalid GTIN format: '{gtin_value}'")
|
||||
|
||||
Reference in New Issue
Block a user