修复条码处理问题:修改format_barcode函数,移除末尾多余的0,确保条码不会超过标准长度

This commit is contained in:
侯欢 2025-05-30 12:14:53 +08:00
parent c9afe413f5
commit 53e907411d

View File

@ -225,4 +225,10 @@ def format_barcode(barcode: Any) -> str:
# 只保留数字字符 # 只保留数字字符
barcode_str = re.sub(r'\D', '', barcode_str) barcode_str = re.sub(r'\D', '', barcode_str)
# 新增处理末尾多余的0标准条码通常为12-13位
if len(barcode_str) > 13 and barcode_str.endswith('0'):
# 从末尾开始移除多余的0直到条码长度为13位或者不再以0结尾
while len(barcode_str) > 13 and barcode_str.endswith('0'):
barcode_str = barcode_str[:-1]
return barcode_str return barcode_str