feat(shipping-notice): 实现货代发货通知的库存全流程与对话交互
This commit is contained in:
1 parent
a5cc48b6aa
commit
2607f4a9f6
26 files changed
+5013
-256
No files matched your search
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
# 常见 Reservation ID:纯数字,如 1000140351(通常 8~12 位)
|
||||
RESERVATION_ID_NUMERIC_RE = re.compile(r"^\d{8,12}$")
|
||||
|
||||
|
||||
def normalize_reservation_id(value: Any) -> str:
|
||||
"""Normalize reservation id; Excel often stores numeric ids as float."""
|
||||
if value is None:
|
||||
return ""
|
||||
|
||||
if isinstance(value, bool):
|
||||
return ""
|
||||
|
||||
if isinstance(value, float):
|
||||
if value != value: # NaN
|
||||
return ""
|
||||
if value.is_integer():
|
||||
return str(int(value))
|
||||
text = str(value).strip()
|
||||
elif isinstance(value, int):
|
||||
text = str(value)
|
||||
else:
|
||||
text = str(value).strip()
|
||||
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
text = text.replace(",", "").replace(",", "").strip()
|
||||
if re.fullmatch(r"\d+\.0+", text):
|
||||
text = text.split(".", 1)[0]
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def looks_like_reservation_id(value: Any) -> bool:
|
||||
text = normalize_reservation_id(value)
|
||||
return bool(text and RESERVATION_ID_NUMERIC_RE.fullmatch(text))
|
||||
Reference in new issue
Block a user