feat(shipping-notice): 完成货代发货通知全门禁恢复MVP收口
完成全门禁恢复MVP版本交付:调整自动上传与重试配置,重构正式执行链路;修复多处代码bug,新增测试与审计工具;更新全流程文档与契约规范。
This commit is contained in:
1 parent
8e0bbf7a81
commit
c94d173f92
181 files changed
+12947
-1724
No files matched your search
@@ -223,6 +223,65 @@ def seed_task_inventory_source(
|
||||
task.inventory_source_method = "rule_exact"
|
||||
task.inventory_source_config_version = inventory_sources_runtime_version()
|
||||
task.inventory_routing_fingerprint = compute_routing_fingerprint(extract_routing_context(task))
|
||||
if getattr(task, '_test_customer_confirmed', False) and not task.order_snapshot_id:
|
||||
freeze_test_task_order_snapshot(task)
|
||||
|
||||
|
||||
def freeze_test_task_order_snapshot(task: "ShippingNotice") -> None:
|
||||
"""将旧式直接构造任务迁移为正式动态订单 + 冻结快照,供库存链路测试复用。"""
|
||||
from app.services.shipping_notice.order_freeze_service import freeze_order_snapshot
|
||||
|
||||
if task.order_snapshot_id:
|
||||
return
|
||||
rows = list(getattr(task, '_test_order_rows', []) or [])
|
||||
if not rows:
|
||||
lines = task.lines_json if isinstance(task.lines_json, list) else []
|
||||
rows = [
|
||||
{
|
||||
'part_number': row.get('part_number'),
|
||||
'reservation_id': row.get('reservation_id'),
|
||||
'qty': row.get('qty'),
|
||||
}
|
||||
for row in lines if isinstance(row, dict)
|
||||
]
|
||||
task._test_order_rows = rows
|
||||
_ensure_test_task_dynamic_order(task)
|
||||
task.order_data_version = int(task.order_data_version or 1)
|
||||
from app import db
|
||||
from app.models import ShippingOrderCustomerMatch, ShippingOrderExtraction
|
||||
db.session.flush()
|
||||
extraction = db.session.get(ShippingOrderExtraction, task.current_order_extraction_id)
|
||||
customer = getattr(getattr(task, 'shipping_case', None), 'customer', None)
|
||||
if extraction is not None and customer is not None and ShippingOrderCustomerMatch.query.filter_by(
|
||||
extraction_id=extraction.id, role='bill_to',
|
||||
).one_or_none() is None:
|
||||
db.session.add(ShippingOrderCustomerMatch(
|
||||
extraction_id=extraction.id, role='bill_to',
|
||||
raw_name=customer.standard_name,
|
||||
normalized_name=str(customer.standard_name or '').upper(), status='confirmed',
|
||||
customer_id=customer.id,
|
||||
customer_name_snapshot=customer.standard_name,
|
||||
customer_short_code_snapshot=customer.short_code,
|
||||
identity_fingerprint='r' * 64,
|
||||
identity_rule_version='test.v1', resolution_method='manual',
|
||||
confirmation_reason='测试确认', confirmed_by_id=None,
|
||||
))
|
||||
db.session.flush()
|
||||
freeze_order_snapshot(
|
||||
task,
|
||||
actor_id=None,
|
||||
expected_order_data_version=int(task.order_data_version),
|
||||
freeze_mode='auto',
|
||||
auto_freeze_policy={
|
||||
'test_fixture': True,
|
||||
'enabled': True,
|
||||
'mode': 'qualified',
|
||||
'qualification_status': 'qualified',
|
||||
'customer_scope_status': 'allowed',
|
||||
'blocking_reason_codes': [],
|
||||
},
|
||||
)
|
||||
db.session.flush()
|
||||
|
||||
|
||||
def _ensure_test_task_dynamic_order(task: "ShippingNotice") -> None:
|
||||
@@ -328,7 +387,7 @@ def inventory_xlsx_with_warehouse(
|
||||
warehouse_id: str,
|
||||
*,
|
||||
sku: str = "A001",
|
||||
reservation_id: str = "R-1",
|
||||
reservation_id: str = "00001",
|
||||
qty: int = 1,
|
||||
) -> "BytesIO":
|
||||
"""生成符合发布解析方案的库存 Excel,供身份、结构和库存解析测试使用。"""
|
||||
@@ -387,6 +446,16 @@ def scheduled_rpa_batch_item(source_code: str, **overrides) -> dict[str, str]:
|
||||
return item
|
||||
|
||||
|
||||
def v2_inventory_batch_payload(payload: dict) -> dict:
|
||||
"""测试构造器:补齐冻结 shipping_inventory_rpa.v2 回调 envelope。"""
|
||||
body = dict(payload or {})
|
||||
run_no = str(body.get('batch_run_no') or body.get('run_no') or '').strip()
|
||||
body.setdefault('schema_version', 'shipping_inventory_rpa.v2')
|
||||
body.setdefault('callback_id', f'test-callback:{run_no or "unknown"}')
|
||||
body.setdefault('batch_run_no', run_no)
|
||||
return body
|
||||
|
||||
|
||||
def rpa_callback_payload(
|
||||
task: "ShippingNotice",
|
||||
file_path: str | Path,
|
||||
@@ -394,14 +463,22 @@ def rpa_callback_payload(
|
||||
run_no: str = "RUN-TEST-001",
|
||||
status: str = "success",
|
||||
) -> dict:
|
||||
"""构造通过单任务 RPA 回调身份/run_no 校验的最小 payload。"""
|
||||
"""构造通过单源 RPA v2 身份/run_no 校验的最小成功 payload。"""
|
||||
return {
|
||||
"schema_version": "shipping_inventory_rpa.v2",
|
||||
"callback_id": f"test-callback:{run_no}",
|
||||
"task_id": task.task_no,
|
||||
"status": status,
|
||||
"file_path": str(file_path),
|
||||
"run_no": run_no,
|
||||
"source_run_no": run_no,
|
||||
"source_code": task.inventory_source_code,
|
||||
"warehouse_id": task.inventory_warehouse_id,
|
||||
"attempt_no": 1,
|
||||
"lease_token": "test-lease-token",
|
||||
"candidate_set_id": 1,
|
||||
"execution_id": 1,
|
||||
"gate_id": 1,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user