按陆运线路叶子收窄工单和看板,避免中港权限看到全部陆运;产品/航线排名只留智能体团队。空运核对卡不再列出空的非必填,报价合计标明约数。中港口语里的车型吨位和按运费比例不再算进金额。报价单上传人显示机器人名,进后台拉标题不再误报没有权限。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1086,6 +1086,29 @@ _RE_FEE_LINE = re.compile(
|
||||
rf"\s*(?P<ccy2>{_CCY_TOKEN}|元)?",
|
||||
re.I,
|
||||
)
|
||||
# 中港陆运口语:「深圳--香港元朗运费10T:1700HKD/车」——车型吨位不是金额。
|
||||
# 必须先于普通费用行,否则会抽成运费=10(WO202610300015)。
|
||||
_RE_FEE_VEHICLE_PRICE = re.compile(
|
||||
r"(?P<name>[\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,24}费)"
|
||||
r"\s*(?:改为|改成|调整为|调整成)?"
|
||||
r"\s*[::=]?"
|
||||
r"\s*(?P<label>\d+(?:\.\d+)?\s*(?:T|吨|HQ|GP|尺))"
|
||||
r"\s*[::=]?\s*"
|
||||
rf"(?:(?P<ccy1>{_CCY_TOKEN})\s*)?"
|
||||
r"(?P<amount>\d+(?:\.\d+)?)"
|
||||
rf"\s*(?P<ccy2>{_CCY_TOKEN}|元)?"
|
||||
r"(?:\s*/\s*车)?",
|
||||
re.I,
|
||||
)
|
||||
# 金额后紧跟车型单位:该数字是吨位/柜型,不是费用金额。
|
||||
_RE_AMOUNT_IS_VEHICLE_UNIT = re.compile(r"^\s*(?:T|吨|HQ|GP|尺)\b", re.I)
|
||||
# 「压夜按运费80%」「压日按运费100%」是比例,禁止落成 HKD 80/100 再加进合计。
|
||||
_RE_FEE_OF_FREIGHT_PCT = re.compile(
|
||||
r"(?P<name>[\u4e00-\u9fff]{1,8}按运费|[\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,16}费)"
|
||||
r"\s*[::=]?\s*"
|
||||
r"(?P<amount>\d+(?:\.\d+)?)\s*%",
|
||||
re.I,
|
||||
)
|
||||
# 多段报价「段1:」「第一段」只是段号,数字不能当费用金额。
|
||||
_RE_SEGMENT_INDEX_LABEL = re.compile(
|
||||
r"(?:段\s*\d+\s*[::]?|第\s*[一二三四五六七八九\d]+\s*段\s*[::]?)",
|
||||
@@ -1366,6 +1389,8 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
|
||||
只认带「费」的中文名或短英文费用码,避免把工单号当金额。
|
||||
句里无币种时继承 baseline_currency(通常是当前 TMS/主账币种),禁止默认 USD。
|
||||
认「费名, KG, 单价…」与「费名_板,单价…」里的计量单位,写入 unit,禁止出单再默认「票」。
|
||||
「运费10T:1700HKD」先认车型价,禁止把吨位 10 当成运费金额。
|
||||
「压夜按运费80%」金额带 %,禁止当绝对金额加进合计。
|
||||
"""
|
||||
project, body = _split_fee_project_prefix(text or "")
|
||||
raw = _ascii_amount(body)
|
||||
@@ -1395,6 +1420,23 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
|
||||
row[key] = val
|
||||
rows.append(row)
|
||||
|
||||
# 先认「运费10T:1700」——车型价;再认「按运费80%」比例;最后才普通金额行。
|
||||
for hit in _RE_FEE_VEHICLE_PRICE.finditer(raw):
|
||||
label = (hit.group("label") or "").strip().replace(" ", "")
|
||||
_add(
|
||||
(hit.group("name") or "").strip(),
|
||||
_ascii_amount(hit.group("amount") or ""),
|
||||
hit.group("ccy1") or hit.group("ccy2") or "",
|
||||
unit="车",
|
||||
vehicle=label,
|
||||
unit_price=_ascii_amount(hit.group("amount") or ""),
|
||||
)
|
||||
for hit in _RE_FEE_OF_FREIGHT_PCT.finditer(raw):
|
||||
name = (hit.group("name") or "").strip()
|
||||
amt = _ascii_amount(hit.group("amount") or "")
|
||||
if not name or not amt:
|
||||
continue
|
||||
_add(name, f"{amt}%", "")
|
||||
priced_hits = 0
|
||||
for hit in _RE_FEE_PRICED.finditer(raw):
|
||||
priced_hits += 1
|
||||
@@ -1427,9 +1469,17 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
|
||||
quantity=quantity,
|
||||
)
|
||||
for hit in _RE_FEE_LINE.finditer(raw):
|
||||
amount = _ascii_amount(hit.group("amount") or "")
|
||||
after_amount = raw[hit.end("amount") :]
|
||||
# 吨位/柜型数字不能当金额(运费10T:… 已被车型价规则吃掉;这里再挡漏网)。
|
||||
if _RE_AMOUNT_IS_VEHICLE_UNIT.match(after_amount):
|
||||
continue
|
||||
# 「80%」保留百分号,合计时只加绝对金额。
|
||||
if re.match(r"\s*%", after_amount or ""):
|
||||
amount = f"{amount}%"
|
||||
_add(
|
||||
(hit.group("name") or "").strip(),
|
||||
_ascii_amount(hit.group("amount") or ""),
|
||||
amount,
|
||||
hit.group("ccy1") or hit.group("ccy2") or "",
|
||||
)
|
||||
for hit in _RE_FEE_CHANGE.finditer(raw):
|
||||
|
||||
@@ -102,10 +102,11 @@ def air_price_lines(
|
||||
facts: dict[str, str] | None = None,
|
||||
) -> list[str]:
|
||||
"""
|
||||
TMS 价格段:费用行、备注、费用合计、报价有效期。
|
||||
TMS 价格段:费用行、备注、费用合计约、报价有效期。
|
||||
|
||||
有单价且有计价单位:单价CNY11/KG。按票:CNY300/票。只有金额:CNY 100.0。
|
||||
备注每次都有,TMS 没带回就「-」。不写时效。
|
||||
合计是预估,不等于最终费用,所以文字里写「费用合计约」。卡片引用条仍叫费用合计。
|
||||
"""
|
||||
from agent.policy.inquiry_copy import money_text, tms_valid_until_display
|
||||
|
||||
@@ -115,7 +116,7 @@ def air_price_lines(
|
||||
lines = [line for line in lines if line]
|
||||
lines.append(f"备注:{_remark_display(src, facts)}")
|
||||
total = money_text(str(src.get("total") or "-").strip() or "-", header_ccy)
|
||||
lines.append(f"费用合计:{total}")
|
||||
lines.append(f"费用合计约:{total}")
|
||||
lines.append(f"报价有效期:{tms_valid_until_display(src)}")
|
||||
return lines
|
||||
|
||||
|
||||
@@ -578,23 +578,30 @@ def air_confirm_card(facts: dict[str, str] | None) -> str:
|
||||
"""
|
||||
确定查价前的核对卡。没有工单号。
|
||||
|
||||
起运地(非必填)紧挨在目的地(必填)上面。
|
||||
报价日期说了写成「报价日期:日期」;没说写成「报价日期(非必填):」,不填当天。
|
||||
必填项一律列出(方便核对)。非必填与报价日期:有识别结果才展示,空着不占行。
|
||||
起运地有值时紧挨在目的地上面。报价日期没说不填当天、也不出空行。
|
||||
"""
|
||||
src = dict(facts or {})
|
||||
lines = ["运输方式(必填):空运"]
|
||||
lines.append(_air_field_line("起运港", _air_known_value(src, "起运港"), required=False))
|
||||
origin_val = _air_known_value(src, "起运港")
|
||||
if origin_val:
|
||||
lines.append(_air_field_line("起运港", origin_val, required=False))
|
||||
for key, _label in AIR_REQUIRED_FIELDS:
|
||||
if key == "报价日期":
|
||||
val = _air_known_value(src, key)
|
||||
# 说了日期就只写日期;没说标明非必填并留空,禁止写成当天。
|
||||
lines.append(f"报价日期:{val}" if val else "报价日期(非必填):")
|
||||
# 说了才展示;没说不占行、不填当天(产品:空非必填不显示)。
|
||||
if val:
|
||||
lines.append(f"报价日期:{val}")
|
||||
continue
|
||||
lines.append(_air_field_line(key, _air_known_value(src, key), required=True))
|
||||
for key, _label in AIR_OPTIONAL_FIELDS:
|
||||
if key == "起运港":
|
||||
continue
|
||||
lines.append(_air_field_line(key, _air_known_value(src, key), required=False))
|
||||
opt_val = _air_known_value(src, key)
|
||||
if not opt_val:
|
||||
continue
|
||||
opt_line = _air_field_line(key, opt_val, required=False)
|
||||
lines.append(opt_line)
|
||||
lines.append("")
|
||||
lines.append(AIR_CONFIRM_TAIL)
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -119,7 +119,8 @@ class AirAddedServicesTests(unittest.TestCase):
|
||||
self.assertEqual(snap["facts"].get("包装方式"), "托盘")
|
||||
card = copy.air_confirm_card(snap["facts"])
|
||||
self.assertIn("包装类型(必填):托盘", card)
|
||||
self.assertIn("增值服务(非必填):\n", card)
|
||||
# 增值服务未识别:核对卡不占空行。
|
||||
self.assertNotIn("增值服务(非必填)", card)
|
||||
self.assertNotIn("托盘、报价日期", card)
|
||||
|
||||
def test_pallet_alone_is_package_and_service(self) -> None:
|
||||
@@ -135,7 +136,12 @@ class AirAddedServicesTests(unittest.TestCase):
|
||||
|
||||
def test_confirm_lists_optional_and_ticket_hides_empty(self) -> None:
|
||||
card = copy.air_confirm_card({"目的港": "吉隆坡", "包装方式": "纸箱"})
|
||||
self.assertIn("增值服务(非必填):", card)
|
||||
# 核对卡空非必填不展示;有值时才出现。
|
||||
self.assertNotIn("增值服务(非必填)", card)
|
||||
with_svc = copy.air_confirm_card(
|
||||
{"目的港": "吉隆坡", "包装方式": "纸箱", "added_services": "托盘"}
|
||||
)
|
||||
self.assertIn("增值服务(非必填):托盘", with_svc)
|
||||
clarify = copy.ask_clarify(
|
||||
facts={"目的港": "吉隆坡"},
|
||||
missing_keys=["品名"],
|
||||
|
||||
@@ -110,17 +110,49 @@ class AirFieldContractTests(unittest.TestCase):
|
||||
"体积": "2",
|
||||
"包装方式": "托盘",
|
||||
"报价日期": "2026-09-22",
|
||||
"起运港": "南京",
|
||||
"货源地": "东莞",
|
||||
}
|
||||
)
|
||||
self.assertNotIn("工单号", text)
|
||||
self.assertIn("起运地(非必填):", text)
|
||||
# 有值的非必填才展示;空着的(贸易条款等)不占行。
|
||||
self.assertIn("起运地(非必填):南京", text)
|
||||
self.assertNotIn("起运港(非必填)", text)
|
||||
self.assertLess(text.index("起运地(非必填):"), text.index("目的地(必填):克拉克"))
|
||||
self.assertLess(text.index("起运地(非必填):南京"), text.index("目的地(必填):克拉克"))
|
||||
self.assertIn("目的地(必填):克拉克", text)
|
||||
self.assertIn("货源地(非必填):", text)
|
||||
self.assertIn("贸易条款(非必填):", text)
|
||||
self.assertIn("货源地(非必填):东莞", text)
|
||||
self.assertIn("报价日期:2026-09-22", text)
|
||||
self.assertNotIn("贸易条款(非必填):", text)
|
||||
self.assertNotIn("货好时间(非必填):", text)
|
||||
self.assertIn(copy.AIR_CONFIRM_TAIL, text)
|
||||
|
||||
def test_confirm_card_hides_empty_optional(self) -> None:
|
||||
"""空运核对卡:未识别的非必填(含空报价日期)不展示。"""
|
||||
text = copy.air_confirm_card(
|
||||
{
|
||||
"目的港": "KUL",
|
||||
"品名": "普货",
|
||||
"件数": "4",
|
||||
"毛重": "636",
|
||||
"体积": "7.497",
|
||||
"包装方式": "托盘",
|
||||
"提货地址": "深圳",
|
||||
"added_services": "托盘",
|
||||
}
|
||||
)
|
||||
self.assertIn("目的地(必填):KUL", text)
|
||||
self.assertIn("提货地址(非必填):深圳", text)
|
||||
self.assertIn("增值服务(非必填):托盘", text)
|
||||
for empty in (
|
||||
"起运地(非必填):",
|
||||
"报价日期(非必填):",
|
||||
"货源地(非必填):",
|
||||
"货好时间(非必填):",
|
||||
"收货地址(非必填):",
|
||||
"贸易条款(非必填):",
|
||||
):
|
||||
self.assertNotIn(empty, text)
|
||||
|
||||
def test_clarify_puts_origin_above_destination(self) -> None:
|
||||
text = copy.ask_clarify(
|
||||
facts={},
|
||||
|
||||
@@ -485,7 +485,7 @@ class AirRouteOptionsTests(unittest.TestCase):
|
||||
"增点费:CNY 100.0",
|
||||
"拆板费:USD 100.0",
|
||||
"备注:-",
|
||||
"费用合计:CNY 5001.0",
|
||||
"费用合计约:CNY 5001.0",
|
||||
"报价有效期:2026-09-30",
|
||||
]
|
||||
),
|
||||
@@ -547,7 +547,7 @@ class AirRouteOptionsTests(unittest.TestCase):
|
||||
self.assertIn("报关费:CNY250/票", text)
|
||||
self.assertIn("增点费:CNY 100.0", text)
|
||||
self.assertIn("备注:其他杂费如有实报实销,不含续页;续页50/票", text)
|
||||
self.assertIn("费用合计:CNY 87150.0", text)
|
||||
self.assertIn("费用合计约:CNY 87150.0", text)
|
||||
self.assertIn("报价有效期:2026-10-31", text)
|
||||
self.assertNotIn("询价字段", text)
|
||||
|
||||
@@ -657,7 +657,8 @@ class AirRouteOptionsTests(unittest.TestCase):
|
||||
flow.on_text(sender_id="u_cabin", text="空运", reply=reply, injected_facts=facts, injected_mode="AIR"),
|
||||
"wait_confirm",
|
||||
)
|
||||
self.assertIn("报价日期(非必填):", replies[-1])
|
||||
# 没说报价日期:核对卡不占空行,也不默认写成当天。
|
||||
self.assertNotIn("报价日期(非必填):", replies[-1])
|
||||
self.assertNotIn("报价日期:2026", replies[-1])
|
||||
self.assertEqual(flow.on_text(sender_id="u_cabin", text="确定", reply=reply), "wait_air_route")
|
||||
self.assertEqual(ledger.queries, 1)
|
||||
|
||||
@@ -972,7 +972,7 @@ class AirTextInquiryTests(unittest.TestCase):
|
||||
self.assertIn("操作费:CNY 1220.00", text)
|
||||
self.assertIn("空运费:USD 1250.00", text)
|
||||
self.assertIn("备注:-", text)
|
||||
self.assertIn("费用合计:CNY 142998.53", text)
|
||||
self.assertIn("费用合计约:CNY 142998.53", text)
|
||||
self.assertNotIn("时效", text)
|
||||
self.assertIn("报价有效期:2026-09-30", text)
|
||||
card_text = copy.quote_area_safe_text(long_quote, business_line="AIR")
|
||||
@@ -1024,7 +1024,7 @@ class AirTextInquiryTests(unittest.TestCase):
|
||||
self.assertNotIn("ZUH-CAN-CRK", detail)
|
||||
self.assertIn("价格方案如下:", detail)
|
||||
self.assertIn("运输费:CNY 11.0", detail)
|
||||
self.assertIn("费用合计:CNY 183370", detail)
|
||||
self.assertIn("费用合计约:CNY 183370", detail)
|
||||
rows = {
|
||||
x["keyname"]: x["value"]
|
||||
for x in copy.scheme_horizontal_rows(
|
||||
|
||||
@@ -1376,6 +1376,27 @@ class SeaGroupCollabFieldTests(unittest.TestCase):
|
||||
self.assertEqual(str(rows["海运费"].get("amount") or ""), "100.00")
|
||||
self.assertEqual(str(rows["燃油附加费"].get("amount") or ""), "15.00")
|
||||
|
||||
def test_land_hk_vehicle_tonnage_not_freight_amount(self) -> None:
|
||||
"""中港陆运「运费10T:1700HKD」不能抽成运费=10;压夜/压日按运费比例不能进合计。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
text = (
|
||||
"深圳--香港元朗运费10T:1700HKD/车\n"
|
||||
"超时费:免等候2小时,超出按200/小时收取;如遇海关查验,查验等候免3小时,"
|
||||
"超过了200/小时,压夜按运费80%,压日按运费100%以上港币报价,不含保,杂费实报实"
|
||||
)
|
||||
quote = extract_product_quote(
|
||||
text, business_line="LAND", transport_mode="陆运", baseline_currency="HKD"
|
||||
)
|
||||
rows = {str(x.get("name") or ""): x for x in (quote.get("fee_rows") or [])}
|
||||
freight = rows.get("深圳--香港元朗运费") or {}
|
||||
self.assertEqual(str(freight.get("amount") or ""), "1700")
|
||||
self.assertEqual(str(freight.get("currency") or ""), "HKD")
|
||||
self.assertEqual(str(rows.get("压夜按运费", {}).get("amount") or ""), "80%")
|
||||
self.assertEqual(str(rows.get("压日按运费", {}).get("amount") or ""), "100%")
|
||||
self.assertEqual(float(quote.get("total") or 0), 1700.0)
|
||||
self.assertNotEqual(str(quote.get("total") or ""), "190.0")
|
||||
|
||||
def test_land_multi_vehicle_rates_not_hq_fee(self) -> None:
|
||||
"""陆运整车多车型价:不能抽成 HQ=19500;要拆成 5T/8T/10T/40HQ/45HQ 价表。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
Reference in New Issue
Block a user