Commit 52241b75 by 黄南光

大幅优化单次补货问题

1 parent 7218f2a7
# CodeGraph data files — local to each machine, not for committing.
# Ignore everything in .codegraph/ except this file itself, so transient
# files (the database, daemon.pid, sockets, logs) never show up in git.
*
!.gitignore
...@@ -40,6 +40,6 @@ tests/ test_system(配置下发 / 加密 / 企微路由 / 话术 / 试 ...@@ -40,6 +40,6 @@ tests/ test_system(配置下发 / 加密 / 企微路由 / 话术 / 试
python -m app.main # 启动(自动迁移数据库) python -m app.main # 启动(自动迁移数据库)
python -m app.cli reset-password admin # 重置密码 python -m app.cli reset-password admin # 重置密码
python -m app.cli drop-legacy # 删除旧版本遗留的 pf_* / rsk_* / inq_* 表(先列出再确认) python -m app.cli drop-legacy # 删除旧版本遗留的 pf_* / rsk_* / inq_* 表(先列出再确认)
python -m pytest # 测试(独立测试库 <DB_NAME>_test,自动创建) python -m pytest # 测试(独立测试库 <DB_NAME>_test,需事先手工建库,不会自动创建)
RUN_LLM=1 python -m pytest tests/test_llm_live.py # 用真实大模型验证选工具 RUN_LLM=1 python -m pytest tests/test_llm_live.py # 用真实大模型验证选工具
``` ```
...@@ -185,11 +185,41 @@ class RestockService: ...@@ -185,11 +185,41 @@ class RestockService:
.order_by(runs_t.c.id.desc()).limit(1)) .order_by(runs_t.c.id.desc()).limit(1))
def scheduled_awaiting_submit(self, sid: int) -> list[dict]: def scheduled_awaiting_submit(self, sid: int) -> list[dict]:
"""今天等着在单据页确认提交的定时补货单(定时 + 手动补充可能各有一张)。""" """等着在单据页确认提交的定时补货单(定时 + 手动补充可能各有一张;确认提交不过期,所以不限今天)。"""
return db.rows(select(runs_t).where(runs_t.c.store_id == sid, runs_t.c.biz_date == self.now(sid).date(), return db.rows(select(runs_t).where(runs_t.c.store_id == sid, runs_t.c.kind == "scheduled",
runs_t.c.kind == "scheduled", runs_t.c.status == "awaiting_submit") runs_t.c.status == "awaiting_submit")
.order_by(runs_t.c.id)) .order_by(runs_t.c.id))
def scheduled_targets(self, sid: int) -> list[dict]:
"""群里问到定时补货时要给链接的单:所有待确认提交的 + 今天待确认的清单,按先后。"""
out = self.scheduled_awaiting_submit(sid)
cur = self.current(sid)
if cur and cur["status"] == "awaiting_confirm" and all(r["id"] != cur["id"] for r in out):
out.append(cur)
return sorted(out, key=lambda r: r["id"])
def scheduled_others(self, sid: int, exclude: int | None = None) -> list[dict]:
"""除了 exclude 之外还要人留意的定时补货单:今天建过采购单 / 还没走完的,加上以前没确认提交的。"""
today = self.now(sid).date()
rows = db.rows(select(runs_t).where(runs_t.c.store_id == sid, runs_t.c.kind == "scheduled",
runs_t.c.status != "superseded").where(
(runs_t.c.status == "awaiting_submit") | (runs_t.c.biz_date == today)).order_by(runs_t.c.id))
return [r for r in rows if r["id"] != exclude and
(r["status"] == "awaiting_submit" or r["order_no"] or r["status"] in OPEN)]
def link_item(self, r: dict) -> dict:
"""一张定时补货单在群消息里的一行:单号、触发方式、阶段、采购单、链接(不是今天的带上日期)。"""
return {"doc_no": r["doc_no"], "trigger_cn": TRIGGER_CN.get(r["trigger"], ""), "stage": r["status"],
"stage_cn": STAGE_CN.get(r["status"], r["status"]), "order_no": r["order_no"] or "",
"biz_date": "" if r["biz_date"] == self.now(r["store_id"]).date() else str(r["biz_date"]),
"link": self.link(r)}
def use_link_text(self, sid: int, targets: list[dict], cancel: bool = False) -> str:
"""引导去单据页的回复:一张时给这一张的链接;两张及以上时明确提示,并把每张的链接都列出来。"""
t = targets[-1]
return self.t(sid, "msg_scheduled_use_link", link=self.link(t), stage=t["status"], order_no=t["order_no"] or "",
items=[self.link_item(r) for r in targets], cancel=cancel)
def po_of(self, rid: int) -> dict | None: def po_of(self, rid: int) -> dict | None:
return db.one(select(po_t).where(po_t.c.run_id == rid).order_by(po_t.c.id.desc()).limit(1)) return db.one(select(po_t).where(po_t.c.run_id == rid).order_by(po_t.c.id.desc()).limit(1))
...@@ -446,9 +476,12 @@ class RestockService: ...@@ -446,9 +476,12 @@ class RestockService:
await self.say(run, self.t(sid, "msg_no_candidates", window=self.window_text(run), stats=stats)) await self.say(run, self.t(sid, "msg_no_candidates", window=self.window_text(run), stats=stats))
return return
self._set(rid, "awaiting_confirm", listed_at=db.now()) self._set(rid, "awaiting_confirm", listed_at=db.now())
# 今天已经有建过采购单的定时补货(如手动补充):明确提示,并把那几张的状态和链接都给出来
others = self.orders_today(sid, run["biz_date"], exclude=rid) others = self.orders_today(sid, run["biz_date"], exclude=rid)
warn = ("\n⚠️ 今天已建采购单 " + "、".join(o["order_no"] for o in others) + warn = ("\n⚠️ 今天已建采购单 " + "、".join(o["order_no"] for o in others) +
",这张按全天出库重新算的,确认前留意别重复订") if others else "" f",这是今天第 {len(others) + 1} 张定时补货单(按全天出库重新算的),确认前留意别重复订:" +
"".join(f"\n· {o['doc_no']}({TRIGGER_CN.get(o['trigger'], '')},{STAGE_CN.get(o['status'], o['status'])},"
f"采购单 {o['order_no']})👉 {self.link(o)}" for o in others)) if others else ""
await self.say(run, self.t(sid, "msg_list", window=self.window_text(run), s=s, link=self.link(run), await self.say(run, self.t(sid, "msg_list", window=self.window_text(run), s=s, link=self.link(run),
cutoff=cfg.cutoff) + warn, at_planners=True) cutoff=cfg.cutoff) + warn, at_planners=True)
...@@ -1192,15 +1225,14 @@ class RestockService: ...@@ -1192,15 +1225,14 @@ class RestockService:
if single: if single:
msg = await self.single_confirm(sid, actor) msg = await self.single_confirm(sid, actor)
return msg, self.ref(single["id"]) return msg, self.ref(single["id"])
pending = self.scheduled_awaiting_submit(sid) targets = self.scheduled_targets(sid)
cur = self.current(sid) if targets:
if pending or (cur and cur["status"] == "awaiting_confirm"): target = targets[-1]
target = pending[-1] if pending else cur
self.audit(sid, actor, "run.chat_confirm_blocked", target_type="run", target_id=str(target["id"]), self.audit(sid, actor, "run.chat_confirm_blocked", target_type="run", target_id=str(target["id"]),
ref=self.ref(target["id"]), detail={"text": actor.extra.get("text", ""), ref=self.ref(target["id"]), detail={"text": actor.extra.get("text", ""),
"status": target["status"]}) "status": target["status"],
return self.t(sid, "msg_scheduled_use_link", link=self.link(target), "docs": [r["doc_no"] for r in targets]})
stage=target["status"], order_no=target["order_no"] or ""), self.ref(target["id"]) return self.use_link_text(sid, targets), self.ref(target["id"])
return self.t(sid, "msg_no_pending"), "" return self.t(sid, "msg_no_pending"), ""
async def chat_submit(self, sid: int, actor: Actor) -> tuple[str, str]: async def chat_submit(self, sid: int, actor: Actor) -> tuple[str, str]:
...@@ -1229,9 +1261,9 @@ class RestockService: ...@@ -1229,9 +1261,9 @@ class RestockService:
if pending: if pending:
target = pending[-1] target = pending[-1]
self.audit(sid, actor, "run.chat_confirm_blocked", target_type="run", target_id=str(target["id"]), self.audit(sid, actor, "run.chat_confirm_blocked", target_type="run", target_id=str(target["id"]),
ref=self.ref(target["id"]), detail={"text": text, "status": target["status"]}) ref=self.ref(target["id"]), detail={"text": text, "status": target["status"],
return self.t(sid, "msg_scheduled_use_link", link=self.link(target), stage=target["status"], "docs": [r["doc_no"] for r in pending]})
order_no=target["order_no"] or ""), self.ref(target["id"]) return self.use_link_text(sid, pending), self.ref(target["id"])
return self.t(sid, "msg_submit_not_ready", doc="", stage="", status=""), "" return self.t(sid, "msg_submit_not_ready", doc="", stage="", status=""), ""
# ====================================================================== 单次补货(群里一句话) # ====================================================================== 单次补货(群里一句话)
...@@ -1416,12 +1448,13 @@ class RestockService: ...@@ -1416,12 +1448,13 @@ class RestockService:
def status_text(self, sid: int) -> str: def status_text(self, sid: int) -> str:
r = self.current(sid) r = self.current(sid)
single = self.single_open(sid) single = self.single_open(sid)
if not r and not single: others = [self.link_item(x) for x in self.scheduled_others(sid, exclude=r["id"] if r else None)]
if not r and not single and not others:
return self.t(sid, "msg_no_run", push_time=self.cfg(sid).push_time) return self.t(sid, "msg_no_run", push_time=self.cfg(sid).push_time)
po = self.po_of(r["id"]) if r else None po = self.po_of(r["id"]) if r else None
return self.t(sid, "msg_status", stage=STAGE_CN.get(r["status"], r["status"]) if r else "", return self.t(sid, "msg_status", stage=STAGE_CN.get(r["status"], r["status"]) if r else "",
order_no=(r or {}).get("order_no"), po_status=(po or {}).get("status") or "", order_no=(r or {}).get("order_no"), po_status=(po or {}).get("status") or "",
link=self.link(r) if r else "", link=self.link(r) if r else "", others=others,
single=single and {"doc": single["doc_no"], "stage": STAGE_CN.get(single["status"]), single=single and {"doc": single["doc_no"], "stage": STAGE_CN.get(single["status"]),
"order_no": single["order_no"] or ""}) "order_no": single["order_no"] or ""})
...@@ -1453,7 +1486,9 @@ class RestockService: ...@@ -1453,7 +1486,9 @@ class RestockService:
"lines": [l.to_dict() for l in lines], "summary": planner.summary(lines), "lines": [l.to_dict() for l in lines], "summary": planner.summary(lines),
"po": db.plain(po) if po else None, "shots": shots, "po": db.plain(po) if po else None, "shots": shots,
"today_orders": [{"doc_no": o["doc_no"], "order_no": o["order_no"], "today_orders": [{"doc_no": o["doc_no"], "order_no": o["order_no"],
"trigger_cn": TRIGGER_CN.get(o["trigger"], "")} "trigger_cn": TRIGGER_CN.get(o["trigger"], ""),
"stage_cn": STAGE_CN.get(o["status"], o["status"]),
"link": f"/m/restock/order/{o['token']}"} # 同站相对链接:页面上直接跳过去
for o in (self.orders_today(sid, r["biz_date"], exclude=r["id"]) for o in (self.orders_today(sid, r["biz_date"], exclude=r["id"])
if r["kind"] == "scheduled" else [])], if r["kind"] == "scheduled" else [])],
"shots_fallback": (po or {}).get("shots_fallback") or "", "shots_fallback": (po or {}).get("shots_fallback") or "",
......
...@@ -53,10 +53,25 @@ TEXTS = [ ...@@ -53,10 +53,25 @@ TEXTS = [
"今天的定时补货已经建过采购单 {{ order_no }}(一天只建一次)。\n单据:{{ link }}", ("order_no", "link"), "今天的定时补货已经建过采购单 {{ order_no }}(一天只建一次)。\n单据:{{ link }}", ("order_no", "link"),
{"order_no": "S2026102701", "link": _LINK}), {"order_no": "S2026102701", "link": _LINK}),
T("restock.msg_scheduled_use_link", "message", "定时补货", "群里回确认(定时补货必须走页面)", T("restock.msg_scheduled_use_link", "message", "定时补货", "群里回确认(定时补货必须走页面)",
"{% if stage == 'awaiting_submit' %}定时补货的采购单 {{ order_no }} 请点开链接核对,没问题点「确认提交」," "{% if items and items|length > 1 %}⚠️ 现在有 {{ items|length }} 张定时补货单(一般一天只有一张,请留意别重复订),"
"{% if cancel %}请在对应链接里操作:待确认提交的点「先不提交」,待确认的点「今天不订」"
"{% else %}群里回复不会提交,请分别点开链接核对:待确认提交的点「确认提交」,待确认的先确认清单{% endif %}\n"
"{% for it in items %}{{ loop.index }}. {{ it.doc_no }}({{ it.trigger_cn }}"
"{% if it.biz_date %},{{ it.biz_date }}{% endif %},{{ it.stage_cn }}"
"{% if it.order_no %},采购单 {{ it.order_no }}{% endif %})👉 {{ it.link }}"
"{% if not loop.last %}\n{% endif %}{% endfor %}"
"{% elif cancel %}定时补货请在链接页面里点"
"{% if stage == 'awaiting_submit' %}「先不提交」{% else %}「今天不订」{% endif %}👉 {{ link }}"
"{% elif stage == 'awaiting_submit' %}定时补货的采购单 {{ order_no }} 请点开链接核对,没问题点「确认提交」,"
"群里回复不会提交 👉\n{{ link }}" "群里回复不会提交 👉\n{{ link }}"
"{% else %}定时补货请点开链接确认清单,不确认不会生成采购单 👉\n{{ link }}{% endif %}", "{% else %}定时补货请点开链接确认清单,不确认不会生成采购单 👉\n{{ link }}{% endif %}",
("link", "stage", "order_no"), {"link": _LINK, "stage": "awaiting_submit", "order_no": "S20261104009"}), ("link", "stage", "order_no", "items", "cancel"),
{"link": _LINK, "stage": "awaiting_submit", "order_no": "S20261104009", "cancel": False,
"items": [{"doc_no": "RP-20261104-1-01", "trigger_cn": "手动补充", "biz_date": "", "stage_cn": "待确认提交",
"order_no": "S20261104008", "link": _LINK},
{"doc_no": "RP-20261104-1-02", "trigger_cn": "定时推送", "biz_date": "", "stage_cn": "待确认提交",
"order_no": "S20261104009", "link": _LINK}]},
"items 是要给链接的全部定时补货单(两张及以上时逐张列出);cancel = 群里说不订 / 不提交时"),
T("restock.msg_scheduled_no_chat", "message", "定时补货", "群里要发起定时补货", T("restock.msg_scheduled_no_chat", "message", "定时补货", "群里要发起定时补货",
"定时补货每天 {{ push_time }} 自动推送,不能在群里发起。\n要单独补某个零件,直接发「零件号 数量」,例如:8713902280 2个", "定时补货每天 {{ push_time }} 自动推送,不能在群里发起。\n要单独补某个零件,直接发「零件号 数量」,例如:8713902280 2个",
("push_time",), {"push_time": "15:00"}), ("push_time",), {"push_time": "15:00"}),
...@@ -190,10 +205,14 @@ TEXTS = [ ...@@ -190,10 +205,14 @@ TEXTS = [
T("restock.msg_status", "message", "查询", "进度查询", T("restock.msg_status", "message", "查询", "进度查询",
"{% if stage %}今天的定时补货:{{ stage }}{% if order_no %},采购单 {{ order_no }}" "{% if stage %}今天的定时补货:{{ stage }}{% if order_no %},采购单 {{ order_no }}"
"{% if po_status %}({{ po_status }}){% endif %}{% endif %}\n{{ link }}{% endif %}" "{% if po_status %}({{ po_status }}){% endif %}{% endif %}\n{{ link }}{% endif %}"
"{% if single %}{% if stage %}\n{% endif %}单次补货 {{ single.doc }}:{{ single.stage }}" "{% if others %}\n⚠️ 另外还有 {{ others|length }} 张定时补货单(一般一天只有一张,请留意别重复订):"
"{% for it in others %}\n· {{ it.doc_no }}({{ it.trigger_cn }}{% if it.biz_date %},{{ it.biz_date }}{% endif %},"
"{{ it.stage_cn }}{% if it.order_no %},采购单 {{ it.order_no }}{% endif %})👉 {{ it.link }}{% endfor %}{% endif %}"
"{% if single %}{% if stage or others %}\n{% endif %}单次补货 {{ single.doc }}:{{ single.stage }}"
"{% if single.order_no %},采购单 {{ single.order_no }}{% endif %}{% endif %}", "{% if single.order_no %},采购单 {{ single.order_no }}{% endif %}{% endif %}",
("stage", "order_no", "po_status", "link", "single"), ("stage", "order_no", "po_status", "link", "single", "others"),
{"stage": "待确认提交", "order_no": "S20261104009", "po_status": "待提交", "link": _LINK, "single": None}), {"stage": "待确认提交", "order_no": "S20261104009", "po_status": "待提交", "link": _LINK, "single": None,
"others": []}),
T("restock.msg_no_run", "message", "查询", "今天还没有补货单", T("restock.msg_no_run", "message", "查询", "今天还没有补货单",
"今天的定时补货还没开始(每天 {{ push_time }} 自动推送)。要单独补某个零件,直接发「零件号 数量」。", "今天的定时补货还没开始(每天 {{ push_time }} 自动推送)。要单独补某个零件,直接发「零件号 数量」。",
("push_time",), {"push_time": "15:00"}), ("push_time",), {"push_time": "15:00"}),
......
...@@ -63,13 +63,11 @@ async def cancel_order(sid: int, actor: Actor, target: dict | None) -> ToolResul ...@@ -63,13 +63,11 @@ async def cancel_order(sid: int, actor: Actor, target: dict | None) -> ToolResul
if msg: if msg:
await _say(sid, target, msg, ref) await _say(sid, target, msg, ref)
return ToolResult(msg or "已取消单次补货", ref=ref) return ToolResult(msg or "已取消单次补货", ref=ref)
pending = svc.scheduled_awaiting_submit(sid) targets = svc.scheduled_targets(sid) # 定时补货在页面上取消;有两张以上时每张的链接都列出来
cur, ref = _scheduled_ref(sid) cur, ref = _scheduled_ref(sid)
if pending: if targets:
msg = "定时补货请在链接页面里点「先不提交」👉 " + svc.link(pending[-1]) msg = svc.use_link_text(sid, targets, cancel=True)
ref = svc.ref(pending[-1]["id"]) ref = svc.ref(targets[-1]["id"])
elif cur and cur["status"] == "awaiting_confirm":
msg = "定时补货请在链接页面里点「今天不订」👉 " + svc.link(cur)
else: else:
msg = svc.t(sid, "msg_no_pending") msg = svc.t(sid, "msg_no_pending")
await _say(sid, target, msg, ref) await _say(sid, target, msg, ref)
...@@ -84,13 +82,11 @@ async def get_status(sid: int, actor: Actor, target: dict | None) -> ToolResult: ...@@ -84,13 +82,11 @@ async def get_status(sid: int, actor: Actor, target: dict | None) -> ToolResult:
async def scheduled_restock(sid: int, actor: Actor, target: dict | None) -> ToolResult: async def scheduled_restock(sid: int, actor: Actor, target: dict | None) -> ToolResult:
"""群里想发起 / 确认定时补货:只回引导语(定时补货只能定时推送或后台按钮触发,确认必须走页面)。""" """群里想发起 / 确认定时补货:只回引导语(定时补货只能定时推送或后台按钮触发,确认必须走页面)。"""
pending = svc.scheduled_awaiting_submit(sid) targets = svc.scheduled_targets(sid)
cur, ref = _scheduled_ref(sid) cur, ref = _scheduled_ref(sid)
if pending or (cur and cur["status"] == "awaiting_confirm"): if targets:
tgt = pending[-1] if pending else cur msg = svc.use_link_text(sid, targets)
msg = svc.t(sid, "msg_scheduled_use_link", link=svc.link(tgt), stage=tgt["status"], ref = svc.ref(targets[-1]["id"])
order_no=tgt["order_no"] or "")
ref = svc.ref(tgt["id"])
else: else:
msg = svc.t(sid, "msg_scheduled_no_chat", push_time=svc.cfg(sid).push_time) msg = svc.t(sid, "msg_scheduled_no_chat", push_time=svc.cfg(sid).push_time)
svc.audit(sid, actor, "run.chat_start_blocked", target_type="run", target_id=str(cur["id"]) if cur else "", svc.audit(sid, actor, "run.chat_start_blocked", target_type="run", target_id=str(cur["id"]) if cur else "",
......
"""测试夹具:连 .env 那台 MySQL 上的独立测试库(默认 <DB_NAME>_test,不存在就自动创建;可用 TEST_DB_NAME 指定)。 """测试夹具:连 .env 那台 MySQL 上的独立测试库(默认 <DB_NAME>_test,必须事先手工建好,不会自动建库;可用 TEST_DB_NAME 指定)。
⚠️ 每次跑测试都会清空测试库里的所有表,所以库名必须以 _test 结尾,否则拒绝运行(保护开发库 / 正式库)。 ⚠️ 每次跑测试都会清空测试库里的所有表,所以库名必须以 _test 结尾,否则拒绝运行(保护开发库 / 正式库)。
企微网关、邮件、大模型都打桩,不会真的发消息。每个用例开始前清空业务数据,重建一套标准门店配置(StoreKit)。 企微网关、邮件、大模型都打桩,不会真的发消息。每个用例开始前清空业务数据,重建一套标准门店配置(StoreKit)。
...@@ -43,9 +43,13 @@ from app.services import edge, im, imhub, notify, settings, stores, texts # noq ...@@ -43,9 +43,13 @@ from app.services import edge, im, imhub, notify, settings, stores, texts # noq
def _reset_db() -> None: def _reset_db() -> None:
root = create_engine(f"{_BASE}/?charset=utf8mb4") root = create_engine(f"{_BASE}/?charset=utf8mb4")
with root.begin() as c: with root.connect() as c:
c.execute(text(f"CREATE DATABASE IF NOT EXISTS `{TEST_DB}` DEFAULT CHARACTER SET utf8mb4")) exists = c.execute(text("SELECT 1 FROM information_schema.schemata WHERE schema_name = :n"),
{"n": TEST_DB}).first()
root.dispose() root.dispose()
if not exists: # 不自动建库:测试库必须由人手工建好
raise SystemExit(f"测试库 {TEST_DB} 不存在。请先手工建库(CREATE DATABASE `{TEST_DB}` "
f"DEFAULT CHARACTER SET utf8mb4),或用 TEST_DB_NAME 指定已有的 _test 库")
eng = db.init_engine() eng = db.init_engine()
with eng.begin() as c: with eng.begin() as c:
names = [r[0] for r in c.execute(text( names = [r[0] for r in c.execute(text(
......
...@@ -389,6 +389,53 @@ def test_manual_run_does_not_affect_schedule(client, admin, outbox, fake_edge, m ...@@ -389,6 +389,53 @@ def test_manual_run_does_not_affect_schedule(client, admin, outbox, fake_edge, m
assert "(手动补充,待提交" in sent[-1] and "(定时推送,已提交)" in sent[-1] assert "(手动补充,待提交" in sent[-1] and "(定时推送,已提交)" in sent[-1]
def test_two_scheduled_orders_prompt_with_both_links(client, admin, outbox, fake_edge):
"""一天出现两张定时补货单(手动补充 + 定时推送)都待确认提交:推送、群里回提交 / 确认 / 不提交、问进度、单据页,
都明确提示有两张,并给出两张各自的链接。"""
k = setup_store(client, admin)
fake_now(hh=10)
k.heartbeat()
assert client.post("/api/restock/runs/start", headers=k.h).json()["result"] == "started"
settle(k)
manual = k.svc().current(k.store_id)
assert confirm(client, manual["token"], state_of(page(client, manual["token"]))).status_code == 200
settle(k)
run = push(k)
pushed = group_msgs(k, outbox)[-1]
assert "这是今天第 2 张定时补货单" in pushed and manual["token"] in pushed and run["token"] in pushed
assert confirm(client, run["token"], state_of(page(client, run["token"]))).status_code == 200
settle(k)
assert [r["id"] for r in k.svc().scheduled_awaiting_submit(k.store_id)] == [manual["id"], run["id"]]
for text, word in (("提交", "群里回复不会提交"), ("确认", "群里回复不会提交"), ("不提交", "「先不提交」")):
say(k, text)
m = group_msgs(k, outbox)[-1]
assert "现在有 2 张定时补货单" in m and word in m, text
assert manual["doc_no"] in m and run["doc_no"] in m and manual["token"] in m and run["token"] in m, text
assert "restock.submit_po" not in fake_edge.calls
say(k, "补货到哪一步了")
m = group_msgs(k, outbox)[-1]
assert "另外还有 1 张定时补货单" in m and manual["token"] in m and run["token"] in m
st = page(client, run["token"])
assert st["today_orders"][0]["link"] == f"/m/restock/order/{manual['token']}"
assert st["today_orders"][0]["stage_cn"] == "待确认提交"
def test_old_scheduled_draft_still_listed_next_day(client, admin, outbox, fake_edge):
"""定时补货确认提交不过期:昨天没提交的单,今天在群里问到时也列出来(带日期和链接)。"""
k = setup_store(client, admin)
run = push(k)
assert confirm(client, run["token"], state_of(page(client, run["token"]))).status_code == 200
settle(k)
fake_now(d=23, hh=9)
k.heartbeat()
say(k, "提交")
m = group_msgs(k, outbox)[-1]
assert run["token"] in m and "群里回复不会提交" in m
say(k, "补货到哪一步了")
m = group_msgs(k, outbox)[-1]
assert "2026-10-22" in m and run["token"] in m
def test_schedule_supersedes_pending_manual_and_waits_busy(client, admin, outbox, fake_edge, monkeypatch): def test_schedule_supersedes_pending_manual_and_waits_busy(client, admin, outbox, fake_edge, monkeypatch):
k = setup_store(client, admin) k = setup_store(client, admin)
fake_now(hh=10) fake_now(hh=10)
......
...@@ -245,8 +245,12 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli ...@@ -245,8 +245,12 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
这段时间里可能有人手工补过货,在途数可能已经变了。请先刷新,再确认。 这段时间里可能有人手工补过货,在途数可能已经变了。请先刷新,再确认。
</div> </div>
<div v-if="st.run.message && editing" class="m-card m-warnbox">{{ st.run.message }}</div> <div v-if="st.run.message && editing" class="m-card m-warnbox">{{ st.run.message }}</div>
<div v-if="st.today_orders?.length && editing" class="m-card m-warnbox"> <!-- 今天不止一张定时补货单:明确提示,每张都给链接(整页跳转,换 token 重新加载) -->
今天已建采购单 {{ st.today_orders.map((o: any) => o.order_no).join('、') }},这张按全天出库重新算,确认前留意别重复订 <div v-if="st.today_orders?.length && (editing || status === 'awaiting_submit')" class="m-card m-warnbox">
⚠️ 今天已经有 {{ st.today_orders.length + 1 }} 张定时补货单(一般一天只有一张),{{ editing ? '这张按全天出库重新算,确认前' : '提交前' }}留意别重复订:
<div v-for="o in st.today_orders" :key="o.doc_no" class="m-other-order">
· <a :href="o.link">{{ o.doc_no }}</a>({{ o.trigger_cn }},{{ o.stage_cn }},采购单 {{ o.order_no }})
</div>
</div> </div>
<!-- 建单结果 --> <!-- 建单结果 -->
......
...@@ -54,6 +54,8 @@ ...@@ -54,6 +54,8 @@
/* 定时补货单据页(一页多态):期望值来源标签、过期提示、折叠组、按钮倒计时、截图兜底说明、确认提交 */ /* 定时补货单据页(一页多态):期望值来源标签、过期提示、折叠组、按钮倒计时、截图兜底说明、确认提交 */
.m-expired { border-color: #f4c7c7; background: #fff5f5; color: #9e2424; font-size: 13px; line-height: 1.7; margin-top: 12px; } .m-expired { border-color: #f4c7c7; background: #fff5f5; color: #9e2424; font-size: 13px; line-height: 1.7; margin-top: 12px; }
.m-warnbox { border-color: #f3dcb6; background: #fffaf2; color: var(--c-warn); font-size: 13px; } .m-warnbox { border-color: #f3dcb6; background: #fffaf2; color: var(--c-warn); font-size: 13px; }
.m-other-order { margin-top: 4px; word-break: break-all; }
.m-other-order a { color: var(--c-primary, #2f6bff); text-decoration: underline; }
.m-fallback { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: #fff1f0; color: #a8071a; font-size: 12.5px; font-weight: 600; } .m-fallback { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: #fff1f0; color: #a8071a; font-size: 12.5px; font-weight: 600; }
.m-progress { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; } .m-progress { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
.m-tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--c-primary-soft); .m-tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--c-primary-soft);
......
...@@ -100,7 +100,7 @@ const pretty = (v: any) => (v === null || v === undefined || v === '' ? '' : typ ...@@ -100,7 +100,7 @@ const pretty = (v: any) => (v === null || v === undefined || v === '' ? '' : typ
<template v-else>等 {{ st.run.triggered_by }} 在群里回「确认」</template> <template v-else>等 {{ st.run.triggered_by }} 在群里回「确认」</template>
</div> </div>
<div v-if="st.today_orders?.length && st.run.status === 'awaiting_confirm'" class="notice warn"> <div v-if="st.today_orders?.length && st.run.status === 'awaiting_confirm'" class="notice warn">
今天已建采购单 {{ st.today_orders.map((o: any) => `${o.order_no}(${o.trigger_cn})`).join('、') }},确认前留意别重复订 今天已建采购单 {{ st.today_orders.map((o: any) => `${o.order_no}(${o.trigger_cn},${o.stage_cn || ''})`).join('、') }},确认前留意别重复订
</div> </div>
<div v-if="st.run.message && ['error', 'scan_retry', 'expired', 'awaiting_confirm'].includes(st.run.status)" class="notice err">{{ st.run.message }}</div> <div v-if="st.run.message && ['error', 'scan_retry', 'expired', 'awaiting_confirm'].includes(st.run.status)" class="notice err">{{ st.run.message }}</div>
<div v-if="st.run.status === 'awaiting_submit' && st.po?.submit_error" class="notice err">上次提交失败:{{ st.po.submit_error }}</div> <div v-if="st.run.status === 'awaiting_submit' && st.po?.submit_error" class="notice err">上次提交失败:{{ st.po.submit_error }}</div>
......
<!-- 补货单列表:定时补货(定时推送 / 手动补充)和单次补货(群里一句话);立即执行补货;导出留痕表。 --> <!-- 补货单列表:定时补货(定时推送 / 手动补充)和单次补货(群里一句话);立即执行补货;导出留痕表(按钮已隐藏,见 SHOW_TRACE_EXPORT)。 -->
<script setup lang="ts"> <script setup lang="ts">
import { Download, Refresh, VideoPlay } from '@element-plus/icons-vue' import { Download, Refresh, VideoPlay } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
...@@ -17,6 +17,7 @@ const router = useRouter() ...@@ -17,6 +17,7 @@ const router = useRouter()
const { rows, total, page, size, loading, filters, load } = usePaged('/api/restock/runs', { filters: { kind: '', status: '' }, query: true }) const { rows, total, page, size, loading, filters, load } = usePaged('/api/restock/runs', { filters: { kind: '', status: '' }, query: true })
const starting = ref(false) const starting = ref(false)
const range = ref<[string, string] | null>(null) const range = ref<[string, string] | null>(null)
const SHOW_TRACE_EXPORT = false // 「导出留痕表」按钮(连同日期范围)暂时隐藏,代码和后端接口保留;要用时改成 true
onMounted(load) onMounted(load)
async function runNow() { async function runNow() {
...@@ -50,8 +51,10 @@ async function exportTrace() { ...@@ -50,8 +51,10 @@ async function exportTrace() {
</PageHeader> </PageHeader>
<Panel flush title="补货单列表"> <Panel flush title="补货单列表">
<template #extra> <template #extra>
<el-date-picker v-model="range" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="w-range" /> <template v-if="SHOW_TRACE_EXPORT">
<el-button :icon="Download" @click="exportTrace">导出留痕表</el-button> <el-date-picker v-model="range" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="w-range" />
<el-button :icon="Download" @click="exportTrace">导出留痕表</el-button>
</template>
</template> </template>
<template #toolbar> <template #toolbar>
<el-radio-group v-model="filters.kind" size="small"> <el-radio-group v-model="filters.kind" size="small">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!