陆运产品价无费名时默认陆运费;看板指标与工单列表共用起止日,趋势按日铺点。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
linmianxun
2026-10-12 14:57:27 +08:00
co-authored by Cursor
parent 739ba401aa
commit 428548c390
10 changed files with 219 additions and 44 deletions
+35 -5
View File
@@ -961,7 +961,32 @@ def _parse_fee_rows(text: str) -> list[dict[str, str]]:
return rows
def extract_product_quote(text: str, *, injected: Optional[dict[str, Any]] = None) -> dict[str, Any]:
def _default_product_fee_name(business_line: str = "", transport_mode: str = "") -> str:
"""
产品文字未点费用名时的默认费目。
必须跟本单运输方式走:陆运→陆运费、空运→空运费、其余→海运费。
禁止陆运单无费名时硬编码「海运费」(WO202610090118「价格为1RMB/KG」)。
"""
line = (business_line or "").strip().upper()
mode = (transport_mode or "").strip()
if line == "LAND" or mode in {"陆运", "LAND", "land"}:
return "陆运费"
if line == "AIR" or mode in {"空运", "AIR", "air"}:
return "空运费"
if line == "SEA" or mode in {"海运", "SEA", "sea"}:
return "海运费"
# 未传业务线时保持旧默认,避免海运调用方漏参后费名变空。
return "海运费"
def extract_product_quote(
text: str,
*,
injected: Optional[dict[str, Any]] = None,
business_line: str = "",
transport_mode: str = "",
) -> dict[str, Any]:
"""
产品文字报价:先按费用行抽,再退回合计/币别。注入优先。
@@ -970,6 +995,7 @@ def extract_product_quote(text: str, *, injected: Optional[dict[str, Any]] = Non
「空运费 单价…金额…」必须保留空运费,金额用「金额」后面的数,不用单价。
陆运集拼:「2-500KG 单价CNY990,燃油附加费率1%,税率6%」走分档单价+费率,
禁止把公斤档下限「2」当成燃油附加费金额(WO021)。
无费用名时按 business_line/transport_mode 默认陆运费/空运费/海运费,禁止陆运硬套海运费。
"""
if isinstance(injected, dict) and (injected.get("total") or injected.get("fee_rows")):
out = dict(injected)
@@ -1015,15 +1041,19 @@ def extract_product_quote(text: str, *, injected: Optional[dict[str, Any]] = Non
if not amount:
return {}
ccy = _currency_of(raw)
default_fee = _default_product_fee_name(business_line, transport_mode)
# 句里已经点了费用名(空运费)时,不能退回默认海运费。
named = re.search(
r"([\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,24}费)",
scrubbed or raw,
)
fee_name = (named.group(1) if named else "") or "海运费"
if fee_name in {"费用", "燃油附加费"}:
# 「燃油附加费率」里的「燃油附加费」不是费用行名;无其它费名时用运费。
fee_name = "海运费" if fee_name == "费用" else "陆运费"
fee_name = (named.group(1) if named else "") or default_fee
if fee_name == "费用":
# 句里只有「费用」没有运输方式前缀时,跟本单默认运费。
fee_name = default_fee
elif fee_name == "燃油附加费":
# 「燃油附加费率」误抽成费名时:陆运/空运用本单默认;海运旧行为落陆运费,避免当海运费金额。
fee_name = default_fee if default_fee != "海运费" else "陆运费"
out = {
"total": amount,
"currency": ccy,
+3 -1
View File
@@ -629,7 +629,9 @@ def apply_air_quote(
fields = extract_air_collab_fields(text)
if fields:
flow.ledger.patch_collab_facts(work_order_no=no, facts=fields, sender_id=sender_id)
quote = injected_quote or extract_product_quote(text) or {}
quote = injected_quote or extract_product_quote(
text, business_line="AIR", transport_mode="空运"
) or {}
if not quote:
send_group_text(client, chat_id, copy.air_quote_not_recognized())
return "quote_empty"
@@ -152,7 +152,15 @@ def handle_multi_inbound(
ticket = _reload(flow, no) or ticket
segments = load_segments(ticket)
target = next((seg for seg in segments if seg.mode == mode), target)
quote = extract_product_quote(text or "", injected=injected_quote)
quote = extract_product_quote(
text or "",
injected=injected_quote,
business_line=str(mode or "").upper(),
transport_mode=(
"陆运" if str(mode or "").upper() == "LAND"
else ("空运" if str(mode or "").upper() == "AIR" else "海运")
),
)
if not quote:
if fields:
return "multi_collab_saved"
+48 -1
View File
@@ -929,7 +929,13 @@ def apply_product_quote(
merged = dict(sess.collab_facts)
merged.update(fields)
sess.collab_facts = merged
quote = extract_product_quote(text, injected=injected_quote)
line = str(view.get("business_line") or view.get("businessLine") or "").strip().upper()
quote = extract_product_quote(
text,
injected=injected_quote,
business_line=line,
transport_mode="陆运" if line == "LAND" else ("海运" if line == "SEA" else ""),
)
if not quote:
logger.info("产品报价未识别 wo=%s text=%s", no, (text or "")[:200])
send_group_text(client, chat_id, copy.group_quote_not_recognized())
@@ -941,7 +947,9 @@ def apply_product_quote(
send_group_text(client, chat_id, copy.group_ask_tms_or_product())
return "wait_tms_choice"
# 分档单价是完整人工价(含费率),禁止和旧错误行(如燃油附加费=2)相加。
# 旧错默认「海运费」的陆运产品价:重报时按本单默认运费对齐后再盖,避免海运费+陆运费并排。
if _quote_fee_rows(base) and not (quote.get("weightPrices") or []):
base = _align_wrong_default_freight(base, quote, business_line=line)
quote = merge_quote_fees(base, quote)
_save_product_quote(flow, no, quote, sess)
ticket2 = _reload(flow, chat_id, no) or ticket
@@ -1627,6 +1635,45 @@ def _merged_total(
return str(src.get("total") or ""), header_ccy
def _align_wrong_default_freight(
base: dict[str, Any] | None,
overlay: dict[str, Any] | None,
*,
business_line: str = "",
) -> dict[str, Any]:
"""
陆运/空运旧产品价若误落成别的运输方式默认费名,重报前改成与新报价同名,便于按行盖价。
只动「海运费/陆运费/空运费/运输费」这类主运费默认名,不碰操作费等真实分项。
"""
src = dict(base or {})
line = (business_line or "").strip().upper()
want = {"LAND": "陆运费", "AIR": "空运费", "SEA": "海运费"}.get(line, "")
if not want:
return src
new_names = {
str(x.get("name") or "").strip()
for x in (overlay or {}).get("fee_rows") or (overlay or {}).get("fee_lines") or []
if isinstance(x, dict)
}
if want not in new_names:
return src
mains = {"海运费", "陆运费", "空运费", "运输费"}
rows = _quote_fee_rows(src)
changed = False
for row in rows:
name = str(row.get("name") or "").strip()
if name in mains and name != want:
row["name"] = want
changed = True
if not changed:
return src
out = dict(src)
out["fee_rows"] = rows
out["fee_lines"] = rows
return out
def merge_quote_fees(base: dict[str, Any] | None, overlay: dict[str, Any] | None) -> dict[str, Any]:
"""
产品按行改价盖到原 TMS 明细上。没点名的费用原样保留。