完善陆海运 TMS 字段与报价单填表:费用数量默认、清空止行安全,写入失败已报价则续办。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -147,6 +147,9 @@ class HttpLedger:
|
||||
"""
|
||||
覆盖本单最新 TMS 快照。选定陆运线路后必须走这里,才能把该条成本写回工单。
|
||||
空报价不打主账,避免把查价结果抹掉。
|
||||
|
||||
若接口暂不可用(热更丢映射常见 404)但查价时主账已落库为已报价,
|
||||
则按成功续办,避免销售侧误报「写入报价失败」。
|
||||
"""
|
||||
no = (work_order_no or "").strip()
|
||||
src = dict(quote or {})
|
||||
@@ -158,11 +161,45 @@ class HttpLedger:
|
||||
idem=f"tms-quote:{no}:{src.get('total') or ''}:{src.get('route_line') or ''}",
|
||||
)
|
||||
if out.get("ok") is False:
|
||||
recovered = self._recover_upsert_if_already_quoted(work_order_no=no, failed=out)
|
||||
if recovered is not None:
|
||||
return recovered
|
||||
return out
|
||||
out.setdefault("ok", True)
|
||||
out.setdefault("status", to_status or "已报价")
|
||||
return out
|
||||
|
||||
def _recover_upsert_if_already_quoted(
|
||||
self,
|
||||
*,
|
||||
work_order_no: str,
|
||||
failed: dict[str, Any],
|
||||
) -> dict[str, Any] | None:
|
||||
"""
|
||||
replaceTmsQuote 失败时,读主账工单:已报价且已有 TMS 价则视为写入成功。
|
||||
查价路径会先 persistHit,接口 404 时工单其实已经有价。
|
||||
"""
|
||||
try:
|
||||
snap = self.get_for_agent(work_order_no=work_order_no, sender_id="")
|
||||
except Exception: # noqa: BLE001 — 兜底读失败仍按原失败返回
|
||||
return None
|
||||
status = str(snap.get("status") or "")
|
||||
tms_hit = snap.get("tms_hit") in (1, "1", True, "true")
|
||||
sale = str(snap.get("sale_price") or snap.get("salePrice") or "").strip()
|
||||
if status == "已报价" and (tms_hit or sale):
|
||||
logger.warning(
|
||||
"upsert_quote 接口失败但工单已报价,按成功续办 wo=%s err=%s",
|
||||
work_order_no,
|
||||
failed.get("error") or failed,
|
||||
)
|
||||
return {
|
||||
"ok": True,
|
||||
"status": "已报价",
|
||||
"recovered": True,
|
||||
"quote_version": snap.get("quote_version") or 1,
|
||||
}
|
||||
return None
|
||||
|
||||
def render_quote(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user