修复条码处理问题:修改format_barcode函数,移除末尾多余的0,确保条码不会超过标准长度
This commit is contained in:
parent
c9afe413f5
commit
53e907411d
@ -225,4 +225,10 @@ def format_barcode(barcode: Any) -> 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
|
||||
Loading…
Reference in New Issue
Block a user