feat(warning): 库存预警邮件表格增加缺少数量列(当前库存 | 缺少数量)

This commit is contained in:
DXC
2026-05-12 15:15:46 +08:00
parent d4bf7c5e99
commit e88de1d408

View File

@ -51,20 +51,19 @@ class InventoryWarningService:
构建纯文本物料清单表格
Args:
rows: [{"name": ..., "spec": ..., "qty": ..., "threshold": ...}, ...]
rows: [{"name": ..., "spec": ..., "qty": ..., "threshold": ..., "shortfall": ...}, ...]
level: "red""yellow",决定阈值列标题
"""
threshold_label = "红色阈值" if level == "red" else "黄色阈值"
lines = [
"名称 | 规格 | 当前库存 | " + threshold_label,
"-" * 60,
"名称 | 规格 | 当前库存 | 缺少数量",
"-" * 55,
]
for r in rows:
name = r.get('name', '-') or '-'
spec = r.get('spec', '-') or '-'
qty = r.get('qty', '-')
th = r.get('threshold', '-')
lines.append(f"{name} | {spec} | {qty} | {th}")
shortfall = r.get('shortfall', '-')
lines.append(f"{name} | {spec} | {qty} | {shortfall}")
return '\n'.join(lines)
@staticmethod
@ -141,6 +140,7 @@ class InventoryWarningService:
'spec': spec,
'qty': round(inv, 2),
'threshold': round(red_th, 2),
'shortfall': round(red_th - inv, 2),
}
if use_yellow_channel:
for email in emails_to_use:
@ -176,6 +176,7 @@ class InventoryWarningService:
'spec': spec,
'qty': round(inv, 2),
'threshold': round(yellow_th, 2),
'shortfall': round(yellow_th - inv, 2),
}
if use_red_channel:
for email in emails_to_use: