feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置 新增收料报表管理的前端页面、路由和侧边栏入口 新增后端收料报表配置接口、数据库模型和RPA脚本 优化发货通知流程的重试策略,将shipping相关job默认不自动重试 移除废弃的库存源确认相关逻辑,更新流程门禁规则 重构订单模板的值适配器模块,新增坐标OCR值适配器 清理前端shipping菜单和action的废弃选项 更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
1 parent
260465b72d
commit
1b6483a4ea
466 files changed
+32115
-33796
No files matched your search
@@ -103,6 +103,61 @@ def non_atomic_part_number_field(raw: dict[str, Any] | None) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _canonicalize_schema_line_aliases(
|
||||
raw: dict[str, Any], *, schema_definition: dict[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
以本次冻结 Schema 的明细字段别名将输入键归一化为 field_code。
|
||||
|
||||
核心逻辑:字段代码优先于别名;同一原始行的多个别名同时映射一个字段时不静默选值,
|
||||
仅保留已存在的字段代码。无 Schema 时只接受调用方提供的正式字段代码。
|
||||
Args:
|
||||
raw: 原始订单行,键可能为邮件/PDF 表头或正式字段代码。
|
||||
schema_definition: 本次 Run 冻结的完整订单 Schema。
|
||||
Returns:
|
||||
使用正式 field_code 作为键的订单行副本。
|
||||
"""
|
||||
canonical = dict(raw)
|
||||
if not schema_definition:
|
||||
return canonical
|
||||
|
||||
aliases: dict[str, str] = {}
|
||||
ambiguous_aliases: set[str] = set()
|
||||
for field in schema_definition.get('fields') or []:
|
||||
if not isinstance(field, dict) or not field.get('enabled', True):
|
||||
continue
|
||||
if str(field.get('scope') or 'line').strip().lower() != 'line':
|
||||
continue
|
||||
field_code = str(field.get('field_code') or '').strip()
|
||||
if not field_code:
|
||||
continue
|
||||
for name in (field_code, field.get('display_name'), *(field.get('aliases') or [])):
|
||||
normalized = norm_header(name)
|
||||
if not normalized:
|
||||
continue
|
||||
previous = aliases.get(normalized)
|
||||
if previous is None:
|
||||
aliases[normalized] = field_code
|
||||
elif previous != field_code:
|
||||
ambiguous_aliases.add(normalized)
|
||||
|
||||
mapped_values: dict[str, Any] = {}
|
||||
ambiguous_codes: set[str] = set()
|
||||
for name, value in raw.items():
|
||||
normalized_name = norm_header(name)
|
||||
field_code = None if normalized_name in ambiguous_aliases else aliases.get(normalized_name)
|
||||
if not field_code or field_code in canonical:
|
||||
continue
|
||||
if field_code in mapped_values:
|
||||
ambiguous_codes.add(field_code)
|
||||
continue
|
||||
mapped_values[field_code] = value
|
||||
for field_code, value in mapped_values.items():
|
||||
if field_code not in ambiguous_codes:
|
||||
canonical[field_code] = value
|
||||
return canonical
|
||||
|
||||
|
||||
def normalize_notice_line(
|
||||
raw: dict[str, Any] | None,
|
||||
*,
|
||||
@@ -121,6 +176,7 @@ def normalize_notice_line(
|
||||
"""
|
||||
if not isinstance(raw, dict):
|
||||
return None
|
||||
raw = _canonicalize_schema_line_aliases(raw, schema_definition=schema_definition)
|
||||
if non_atomic_part_number_field(raw):
|
||||
return None
|
||||
|
||||
@@ -130,7 +186,7 @@ def normalize_notice_line(
|
||||
if not part_number or "/" in part_number:
|
||||
return None
|
||||
|
||||
qty = parse_number(raw.get("qty") if raw.get("qty") is not None else raw.get("quantity"))
|
||||
qty = parse_number(raw.get("qty"))
|
||||
if qty is None or qty <= 0:
|
||||
return None
|
||||
|
||||
@@ -145,89 +201,51 @@ def normalize_notice_line(
|
||||
if raw_uom and field_enabled("uom"):
|
||||
line["uom"] = raw_uom
|
||||
|
||||
line_no = normalize_line_no(
|
||||
raw.get("line_no")
|
||||
or raw.get("lineNo")
|
||||
or raw.get("item")
|
||||
or raw.get("item_no")
|
||||
or raw.get("itemNo")
|
||||
or raw.get("Item")
|
||||
or raw.get("Item No")
|
||||
)
|
||||
line_no = normalize_line_no(raw.get("line_no"))
|
||||
if line_no and field_enabled("line_no"):
|
||||
line["line_no"] = line_no
|
||||
|
||||
reservation_id = extract_reservation_id(
|
||||
raw.get("reservation_id")
|
||||
or raw.get("reservationId")
|
||||
or raw.get("com_id")
|
||||
or raw.get("reservation_order")
|
||||
or raw.get("pr_number")
|
||||
or raw.get("prNumber")
|
||||
or raw.get("PR Number")
|
||||
)
|
||||
reservation_id = extract_reservation_id(raw.get("reservation_id"))
|
||||
if reservation_id and field_enabled("reservation_id"):
|
||||
line["reservation_id"] = reservation_id
|
||||
evidence = raw.get("reservation_id_evidence")
|
||||
if isinstance(evidence, dict) and field_enabled("reservation_id"):
|
||||
line["reservation_id_evidence"] = dict(evidence)
|
||||
|
||||
unit_price = parse_number(raw.get("unit_price") if raw.get("unit_price") is not None else raw.get("price"))
|
||||
unit_price = parse_number(raw.get("unit_price"))
|
||||
if unit_price is not None and field_enabled("unit_price"):
|
||||
line["unit_price"] = unit_price
|
||||
|
||||
amount = parse_number(raw.get("amount") if raw.get("amount") is not None else raw.get("total"))
|
||||
amount = parse_number(raw.get("amount"))
|
||||
if amount is not None and field_enabled("amount"):
|
||||
line["amount"] = amount
|
||||
elif unit_price is not None and field_enabled("amount"):
|
||||
line["amount"] = round(unit_price * qty, 4)
|
||||
|
||||
currency = normalize_currency(raw.get("currency") or raw.get("Currency"))
|
||||
currency = normalize_currency(raw.get("currency"))
|
||||
if not currency:
|
||||
currency = extract_currency(
|
||||
raw.get("unit_price"),
|
||||
raw.get("price"),
|
||||
raw.get("amount"),
|
||||
raw.get("total"),
|
||||
raw.get("unit_price"), raw.get("amount"),
|
||||
)
|
||||
if currency and field_enabled("currency"):
|
||||
line["currency"] = currency
|
||||
|
||||
required_date = normalize_required_date(
|
||||
raw.get("required_date")
|
||||
or raw.get("delivery_date")
|
||||
or raw.get("deliveryDate")
|
||||
or raw.get("eta")
|
||||
or raw.get("ETA")
|
||||
)
|
||||
required_date = normalize_required_date(raw.get("required_date"))
|
||||
if required_date and field_enabled("required_date"):
|
||||
line["required_date"] = required_date
|
||||
|
||||
optional_aliases = {
|
||||
"po_number": ("po_number", "poNumber", "PO", "PO Number"),
|
||||
"allocation_id": ("allocation_id", "allocationId", "Allocation ID"),
|
||||
"inventory_source_hint": (
|
||||
"inventory_source_hint",
|
||||
"Source Type",
|
||||
"Hub Code",
|
||||
"Hub",
|
||||
"HUB",
|
||||
),
|
||||
"customer_part_number": ("customer_part_number", "Customer Part Number", "Customer PN", "Allocated HHPN"),
|
||||
"aws_part_number": ("aws_part_number", "AWS Sku", "AWS SKU"),
|
||||
}
|
||||
optional_fields = (
|
||||
"po_number", "allocation_id", "inventory_source_hint",
|
||||
"customer_part_number", "aws_part_number", "line_remark",
|
||||
)
|
||||
if composite.get('customer_part_number'):
|
||||
if field_enabled('customer_part_number'):
|
||||
line['customer_part_number'] = composite['customer_part_number']
|
||||
for field, aliases in optional_aliases.items():
|
||||
value = next((str(raw.get(alias) or "").strip() for alias in aliases if raw.get(alias)), "")
|
||||
for field in optional_fields:
|
||||
value = str(raw.get(field) or "").strip()
|
||||
if value and field_enabled(field):
|
||||
line[field] = value
|
||||
|
||||
remark = str(raw.get("remark") or raw.get("note") or "").strip()
|
||||
if remark and field_enabled("remark"):
|
||||
line["remark"] = remark
|
||||
|
||||
return line
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user