2 Commits

2 changed files with 8 additions and 7 deletions

View File

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

View File

@ -26,7 +26,7 @@ def _run_warning_job():
scheduler = BackgroundScheduler(timezone=beijing_tz) scheduler = BackgroundScheduler(timezone=beijing_tz)
scheduler.add_job( scheduler.add_job(
func=_run_warning_job, func=_run_warning_job,
trigger=CronTrigger(hour=14, minute=32, timezone=beijing_tz), trigger=CronTrigger(hour=9, minute=30, timezone=beijing_tz),
id='inventory_warning_daily', id='inventory_warning_daily',
name='库存预警每日邮件发送', name='库存预警每日邮件发送',
replace_existing=True replace_existing=True