fix(shipping-notice): 修复发货单审核视图重试逻辑及RPA回调缺仓库的处理
This commit is contained in:
1 parent
fac960aa16
commit
d7b9b9c5ff
4 files changed
+154
-8
No files matched your search
@@ -1629,10 +1629,14 @@ def _handle_rpa_inventory_failed(
|
||||
*,
|
||||
commit: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
"""处理 failed 回调:累计尝试并在耗尽后转人工上传兜底。"""
|
||||
"""处理 failed 回调:记录稳定失败码、累计尝试并在耗尽后转人工上传兜底。"""
|
||||
apply_task_transition(task, TaskTransition.INV_UNAVAIL)
|
||||
task.error_message = str(payload.get("error_message") or "RPA inventory export failed")[:500]
|
||||
log_task_event(task, "inventory_rpa_failed", {"error": task.error_message, "rpa_runtime": runtime})
|
||||
log_task_event(task, "inventory_rpa_failed", {
|
||||
"error": task.error_message,
|
||||
"error_code": str(payload.get("error_code") or "rpa_export_failed"),
|
||||
"rpa_runtime": runtime,
|
||||
})
|
||||
db.session.flush()
|
||||
attempts = inventory_rpa_attempts(task)
|
||||
if attempts >= max_rpa_inventory_attempts():
|
||||
@@ -2532,9 +2536,58 @@ def process_rpa_report_inventory_batch(payload: dict[str, Any]) -> dict[str, Any
|
||||
# 定时批量成功项必须显式携带 Warehouse 身份;先做身份校验,
|
||||
# 避免缺 Warehouse 被后续文件路径错误遮蔽。
|
||||
if not warehouse_id:
|
||||
# [STEP] RPA 声称导出成功但缺少仓库身份时,文件绝不能成为可匹配
|
||||
# 快照;同时必须终态化本次逐源 Attempt/准备轮次,避免前端永久显示
|
||||
# “处理中”或允许重复触发同一运行中的 Attempt。
|
||||
if task and source_run_no_item and structured_attempt:
|
||||
from app.services.shipping_notice.per_source_rpa_service import per_source_callback_handler
|
||||
|
||||
per_source_callback_handler(
|
||||
task,
|
||||
source_code=source_code,
|
||||
run_no=source_run_no_item,
|
||||
callback_payload={
|
||||
**dict(merged_item),
|
||||
'error_code': 'warehouse_id_missing',
|
||||
'error_message': 'RPA 回调缺少 warehouse_id,无法确认库存归属。',
|
||||
},
|
||||
)
|
||||
if task:
|
||||
runtime = _save_last_inventory_rpa_runtime(task, merged_item)
|
||||
_handle_rpa_inventory_failed(
|
||||
task,
|
||||
{
|
||||
**dict(merged_item),
|
||||
'error_code': 'warehouse_id_missing',
|
||||
'error_message': 'RPA 回调缺少 warehouse_id,无法确认库存归属。',
|
||||
},
|
||||
runtime,
|
||||
commit=False,
|
||||
)
|
||||
# 与显式 failed 回调保持相同的 Gate 收口语义:Task 已从
|
||||
# rpa_pending 转为可重试失败,正式 Execution 不能继续停在
|
||||
# waiting_external,否则右侧页面会显示过期的“处理中”。
|
||||
if task.active_process_execution_id:
|
||||
from app.models import ShippingProcessExecution
|
||||
from app.services.shipping_notice.process_gate_bridge import sync_fulfillment_gates_from_task
|
||||
|
||||
execution = db.session.get(
|
||||
ShippingProcessExecution,
|
||||
int(task.active_process_execution_id),
|
||||
)
|
||||
if (
|
||||
execution is not None
|
||||
and int(getattr(execution, 'task_id', 0) or 0) == int(task.id)
|
||||
and str(getattr(execution, 'status', '') or '').strip().lower() != 'superseded'
|
||||
):
|
||||
sync_fulfillment_gates_from_task(
|
||||
execution=execution,
|
||||
actor_type='system',
|
||||
)
|
||||
failed.append({
|
||||
"source_code": source_code,
|
||||
"warehouse_id": warehouse_id,
|
||||
"task_no": task_no or None,
|
||||
"error": "warehouse_id_missing",
|
||||
})
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user