feat(shipping-notice): 完成货代发货通知全流程开发与代码重构
- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑 - 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示 - 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败 - 新增路径工具类统一管理相对路径,优化配置文件处理逻辑 - 归档旧文档,将部署、Dify配置合并到`shipping_notice.md` - 新增完整单元测试与集成测试覆盖核心流程 - 更新前端国际化与会话管理逻辑,优化界面交互
This commit is contained in:
1 parent
b62082758b
commit
8deae3146b
65 files changed
+6477
-1937
No files matched your search
@@ -6,11 +6,38 @@ from app.services.shipping_notice.notice_lines import (
|
||||
validate_notice_lines,
|
||||
)
|
||||
from app.services.shipping_notice.reservation_id import (
|
||||
extract_reservation_id,
|
||||
find_reservation_id_in_document,
|
||||
looks_like_reservation_id,
|
||||
normalize_reservation_id,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_reservation_id_from_pr_number():
|
||||
assert extract_reservation_id("ADU_S-ENCWIW260528126265@1000140351") == "1000140351"
|
||||
assert find_reservation_id_in_document("PR Number: ADU_S-ENCWIW260528126265@1000140351") == "1000140351"
|
||||
|
||||
|
||||
def test_wistron_po_table_with_pr_number_in_document():
|
||||
text = """
|
||||
Vendor: HOXIN
|
||||
PR Number: ADU_S-ENCWIW260528126265@1000140351
|
||||
Line No\tMaterial\tVendor Part Number\tDescription\tQuantity\tETA\tUnit Price\tAmount
|
||||
10\t504-010213-001\tB3-A08AR11000001\tENCLOSURE\t9.000 PCS\t2026/06/15\t1,607.72 USD\t14,469.48 USD
|
||||
"""
|
||||
lines = parse_notice_table_text(text)
|
||||
assert len(lines) == 1
|
||||
assert lines[0]["sku"] == "504-010213-001"
|
||||
assert lines[0]["line_no"] == "10"
|
||||
assert lines[0]["qty"] == 9.0
|
||||
assert lines[0]["unit_price"] == 1607.72
|
||||
assert lines[0]["amount"] == 14469.48
|
||||
assert lines[0]["reservation_id"] == "1000140351"
|
||||
assert lines[0]["required_date"] == "2026-06-15"
|
||||
assert lines[0]["vendor_part_number"] == "B3-A08AR11000001"
|
||||
assert lines[0]["currency"] == "USD"
|
||||
|
||||
|
||||
def test_normalize_reservation_id_from_excel_float():
|
||||
assert normalize_reservation_id(1000140351.0) == "1000140351"
|
||||
assert normalize_reservation_id("1000140351.0") == "1000140351"
|
||||
@@ -55,18 +82,60 @@ def test_normalize_notice_line_aliases():
|
||||
"quantity": "3",
|
||||
"com_id": "COM-99",
|
||||
"price": "12.5",
|
||||
"delivery_date": "2026/06/15",
|
||||
"vendorPartNumber": "VND-001",
|
||||
"currency": "USD",
|
||||
"line_no": "10",
|
||||
}
|
||||
)
|
||||
assert line == {
|
||||
"line_no": "10",
|
||||
"sku": "A-001",
|
||||
"qty": 3.0,
|
||||
"uom": "EA",
|
||||
"reservation_id": "COM-99",
|
||||
"unit_price": 12.5,
|
||||
"amount": 37.5,
|
||||
"currency": "USD",
|
||||
"required_date": "2026-06-15",
|
||||
"vendor_part_number": "VND-001",
|
||||
}
|
||||
|
||||
|
||||
def test_enrich_notice_with_document_currency():
|
||||
from app.services.shipping_notice.notice_lines import enrich_notice_with_document_currency
|
||||
|
||||
parsed = enrich_notice_with_document_currency(
|
||||
{
|
||||
"currency": "USD",
|
||||
"lines": [{"sku": "A-001", "qty": 1, "uom": "EA"}, {"sku": "B-002", "qty": 2, "currency": "EUR", "uom": "EA"}],
|
||||
}
|
||||
)
|
||||
assert parsed["lines"][0]["currency"] == "USD"
|
||||
assert parsed["lines"][1]["currency"] == "EUR"
|
||||
|
||||
|
||||
def test_extract_currency_from_price_string():
|
||||
from app.services.shipping_notice.notice_lines import _extract_currency
|
||||
|
||||
assert _extract_currency("1,607.72 USD") == "USD"
|
||||
assert _extract_currency("$15.5") == "USD"
|
||||
assert _extract_currency("¥100") == "CNY"
|
||||
|
||||
|
||||
def test_enrich_notice_with_document_required_date():
|
||||
from app.services.shipping_notice.notice_lines import enrich_notice_with_document_required_date
|
||||
|
||||
parsed = enrich_notice_with_document_required_date(
|
||||
{
|
||||
"required_date": "2026-06-20",
|
||||
"lines": [{"sku": "A-001", "qty": 1, "uom": "EA"}, {"sku": "B-002", "qty": 2, "required_date": "2026-06-18", "uom": "EA"}],
|
||||
}
|
||||
)
|
||||
assert parsed["lines"][0]["required_date"] == "2026-06-20"
|
||||
assert parsed["lines"][1]["required_date"] == "2026-06-18"
|
||||
|
||||
|
||||
def test_extract_notice_fields_structured():
|
||||
structured = {
|
||||
"customer_name": "ACME",
|
||||
|
||||
Reference in new issue
Block a user