Files
syops/backend/app/services/shipping_notice/po_number.py
T
hugo 8deae3146b feat(shipping-notice): 完成货代发货通知全流程开发与代码重构
- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑
- 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示
- 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败
- 新增路径工具类统一管理相对路径,优化配置文件处理逻辑
- 归档旧文档,将部署、Dify配置合并到`shipping_notice.md`
- 新增完整单元测试与集成测试覆盖核心流程
- 更新前端国际化与会话管理逻辑,优化界面交互
2026-06-04 15:26:34 +08:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
import re
from typing import Any
_PO_NUMBER_PATTERNS = (
r"(?i)(?:PO|P\.O\.)\s*(?:Number|No\.?|#)?\s*[::]\s*([A-Za-z0-9][A-Za-z0-9\-_/]*)",
r"(?i)Purchase\s+Order\s*(?:Number|No\.?|#)?\s*[::]\s*([A-Za-z0-9][A-Za-z0-9\-_/]*)",
r"(?:采购订单号|采购单号|订单号|PO号)\s*[::]\s*([A-Za-z0-9][A-Za-z0-9\-_/]*)",
)
def normalize_po_number(value: Any) -> str:
text = str(value or "").strip()
if not text:
return ""
if text.lower() in {"number", "no", "n/a", "na", "none"}:
return ""
return text
def find_po_number_in_document(text: str) -> str:
raw = str(text or "")
if not raw.strip():
return ""
for pattern in _PO_NUMBER_PATTERNS:
match = re.search(pattern, raw)
if match:
return normalize_po_number(match.group(1))
return ""
def enrich_notice_with_po_number(parsed: dict[str, Any], *, raw_text: str = "") -> dict[str, Any]:
po_number = normalize_po_number(
parsed.get("po_number") or parsed.get("PO Number") or parsed.get("purchase_order_number")
)
if not po_number:
po_number = find_po_number_in_document(raw_text)
if po_number:
parsed["po_number"] = po_number
return parsed