修复条码验证问题:在验证阶段处理过长条码,移除末尾多余的0,确保条码不会超过标准长度
This commit is contained in:
parent
53e907411d
commit
556f8d8020
@ -60,6 +60,20 @@ class ProductValidator:
|
|||||||
original_barcode = barcode_clean
|
original_barcode = barcode_clean
|
||||||
barcode_clean = '6' + barcode_clean[1:]
|
barcode_clean = '6' + barcode_clean[1:]
|
||||||
logger.info(f"修正条码前缀 5->6: {original_barcode} -> {barcode_clean}")
|
logger.info(f"修正条码前缀 5->6: {original_barcode} -> {barcode_clean}")
|
||||||
|
|
||||||
|
# 新增:处理14位条码,如果多余长度都是0,截断为13位
|
||||||
|
if len(barcode_clean) > 13:
|
||||||
|
original_length = len(barcode_clean)
|
||||||
|
# 检查多余部分是否都是0
|
||||||
|
if barcode_clean.endswith('0'):
|
||||||
|
# 从末尾开始移除0,直到条码长度为13位或不再以0结尾
|
||||||
|
while len(barcode_clean) > 13 and barcode_clean.endswith('0'):
|
||||||
|
barcode_clean = barcode_clean[:-1]
|
||||||
|
logger.info(f"修正条码长度: 从{original_length}位截断到{len(barcode_clean)}位")
|
||||||
|
else:
|
||||||
|
error_message = f"条码长度异常: {barcode_clean}, 长度={len(barcode_clean)}"
|
||||||
|
logger.warning(error_message)
|
||||||
|
return False, barcode_clean, error_message
|
||||||
|
|
||||||
# 验证条码长度
|
# 验证条码长度
|
||||||
if len(barcode_clean) < 8 or len(barcode_clean) > 13:
|
if len(barcode_clean) < 8 or len(barcode_clean) > 13:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user