fix(chat-input-bar,shipping-process-gate): 修复库存RPA重试按钮隐藏问题
- 重构发货通知流程的Gate投影逻辑,统一库存RPA失败后的恢复动作,避免被降级为人工上传入口 - 新增全覆盖单元测试验证恢复动作逻辑
This commit is contained in:
1 parent
3c0e08377c
commit
eee9163ce0
12 files changed
+350
-78
No files matched your search
@@ -421,6 +421,16 @@ def is_business_user_action(action_code: str | None) -> bool:
|
||||
return bool(code) and code in PROCESS_GATE_BUSINESS_USER_ACTION_CODES
|
||||
|
||||
|
||||
def inventory_preparation_primary_action(status: str | None) -> str | None:
|
||||
"""裁决库存准备 Gate 面向业务用户的主动作。"""
|
||||
normalized_status = str(status or '').strip().lower()
|
||||
if normalized_status == 'waiting_external':
|
||||
return 'poll_inventory_preparation'
|
||||
if normalized_status in {'blocked_manual', 'blocked_retryable'}:
|
||||
return 'retry_inventory_preparation'
|
||||
return None
|
||||
|
||||
|
||||
def is_technical_gate_party(responsible_party: str | None) -> bool:
|
||||
"""判断责任方是否为技术自动 Gate(system/worker)。"""
|
||||
return str(responsible_party or '').strip() in PROCESS_GATE_TECHNICAL_PARTIES
|
||||
|
||||
@@ -779,7 +779,11 @@ def _handle_retry_inventory_preparation(
|
||||
operation_id=str(payload.get('operation_id') or '').strip() or None,
|
||||
gate_attempt_id=int(payload.get('attempt_id')) if payload.get('attempt_id') else None,
|
||||
)
|
||||
response = ensure_inventory(_task_payload(execution, payload))
|
||||
inventory_payload = _task_payload(execution, payload)
|
||||
# 用户重试必须进入逐源 RPA Attempt,生成新的 inventory trigger;轮询动作继续复用普通模式。
|
||||
if payload.get('action_code') != 'poll_inventory_preparation':
|
||||
inventory_payload['mode'] = 'retry_rpa'
|
||||
response = ensure_inventory(inventory_payload)
|
||||
if preparation_round is not None:
|
||||
from app.services.shipping_notice.inventory_recovery_service import sync_inventory_preparation_round
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ from app.services.shipping_notice.process_gate_contract import (
|
||||
PROCESS_GATE_RECOVERABLE_STATUSES,
|
||||
action_presentation,
|
||||
get_process_gate_definition,
|
||||
inventory_preparation_primary_action,
|
||||
is_business_user_action,
|
||||
)
|
||||
from app.services.shipping_notice.process_gate_error_sanitizer import sanitize_gate_error_text
|
||||
@@ -83,6 +84,87 @@ def _projection_primary_next_action(*, gate_code: str, status: str) -> str | Non
|
||||
return str(value) if value else None
|
||||
|
||||
|
||||
# 库存 RPA / 准备失败原因:统一由业务用户触发「重新获取库存」(retry_inventory_preparation)。
|
||||
# 与 error_explainability_contract.EXPLAINABILITY_REASON_META 中 inventory_file_empty 等
|
||||
# 的 prescribed action 保持一致;这些原因在 process_gate_contract 中分类为 retryable_tech,
|
||||
# 但因 inventory_preparation 的 responsible_party='worker',历史投影会按「worker/retry_ 技术
|
||||
# 动作屏蔽」规则将其从业务按钮隐藏,导致用户只能看到被降级的人工上传入口。
|
||||
def _resolve_recovery_next_action(
|
||||
*, blocking: dict[str, Any] | None, full: dict[str, Any], execution: Any,
|
||||
) -> tuple[str | None, bool]:
|
||||
"""
|
||||
单一裁决:由阻断原因码 / Gate 状态推导业务用户主恢复动作。
|
||||
|
||||
[STEP 1] 库存 RPA 失败(inventory_preparation Gate + retryable_tech 原因码)统一下发
|
||||
``retry_inventory_preparation``(重新获取库存),绕过历史「worker/retry_ 技术动作屏蔽」
|
||||
分支,使业务用户在库存 RPA 失败时可直接重试,而非被降级为人工上传入口。
|
||||
[STEP 2] 货代上传 RPA / 人工交接失败保持统一 RPA 重试入口。
|
||||
[STEP 3] 其余沿用 Gate 合同默认 next_action(primary 或按 status 推导),并保留
|
||||
RecoveryPlan 复核入口兜底;技术责任方的 retry_* 仍默认仅作系统执行动作。
|
||||
"""
|
||||
if not blocking:
|
||||
return None, False
|
||||
blocking_gate_code = str((blocking or {}).get('gate_code') or '').strip().lower()
|
||||
normalized_reason = str((blocking or {}).get('blocking_reason_code') or '').strip().lower()
|
||||
status = str((blocking or {}).get('status') or '').strip().lower()
|
||||
|
||||
# [STEP 1] 库存准备失败统一允许业务用户手动重新获取库存;人工上传是辅助输入入口。
|
||||
if blocking_gate_code == 'inventory_preparation':
|
||||
inventory_action = inventory_preparation_primary_action(status)
|
||||
if inventory_action:
|
||||
return inventory_action, False
|
||||
|
||||
# [STEP 2] 货代上传 RPA 失败 / 人工交接失败:保持统一的 RPA 重试入口。
|
||||
if (
|
||||
blocking_gate_code == 'freight_upload_rpa'
|
||||
and normalized_reason in {'upload_rpa_failed', 'upload_rpa_login_failed', 'upload_platform_rejected'}
|
||||
):
|
||||
return 'retry_freight_upload_rpa', False
|
||||
if (
|
||||
blocking_gate_code == 'manual_upload_handoff'
|
||||
and normalized_reason in {'manual_upload_pending', 'upload_result_unknown'}
|
||||
):
|
||||
return 'retry_freight_upload_rpa', False
|
||||
|
||||
# [STEP 3] 其余沿用 Gate 合同默认 next_action(primary 或按 status 推导)。
|
||||
next_action = full.get('primary_next_action_code') or _projection_primary_next_action(
|
||||
gate_code=blocking_gate_code, status=status,
|
||||
)
|
||||
technical_auto_only = False
|
||||
# 技术责任方的 retry_* 只作为系统执行动作,不能直接充当业务用户主按钮;
|
||||
# RecoveryPlan 仍可在下方投影为经过权限校验的恢复入口。
|
||||
if next_action and (
|
||||
not is_business_user_action(str(next_action))
|
||||
or (
|
||||
str(full.get('responsible_party') or '').strip().lower() in {'system', 'worker'}
|
||||
and str(next_action).startswith('retry_')
|
||||
)
|
||||
):
|
||||
next_action = None
|
||||
technical_auto_only = True
|
||||
|
||||
# RecoveryPlan 复核入口兜底(inventory_matching / inventory_sufficiency)。
|
||||
if not next_action:
|
||||
recovery_targets = full.get('recovery_targets') or []
|
||||
if recovery_targets and blocking_gate_code == 'inventory_matching':
|
||||
next_action = 'open_inventory_match_review'
|
||||
technical_auto_only = False
|
||||
elif recovery_targets and blocking_gate_code == 'inventory_sufficiency':
|
||||
next_action = 'open_shortage_review'
|
||||
technical_auto_only = False
|
||||
# 库存准备/匹配/货代上传 RPA 在 blocked_retryable 时仍允许业务用户恢复。
|
||||
if not next_action and blocking_gate_code in {
|
||||
'inventory_preparation', 'inventory_matching', 'freight_upload_rpa',
|
||||
}:
|
||||
candidate = _projection_primary_next_action(
|
||||
gate_code=blocking_gate_code, status=status,
|
||||
)
|
||||
if candidate and is_business_user_action(candidate):
|
||||
next_action = candidate
|
||||
technical_auto_only = False
|
||||
return next_action, technical_auto_only
|
||||
|
||||
|
||||
def serialize_gate_attempt(
|
||||
attempt: ShippingProcessGateAttempt | None,
|
||||
*,
|
||||
@@ -430,80 +512,13 @@ def project_user_gate_summary(execution: ShippingProcessExecution) -> dict[str,
|
||||
if diagnostic_hint:
|
||||
break
|
||||
reason_code = (blocking or {}).get('blocking_reason_code')
|
||||
next_action = full.get('primary_next_action_code') or (
|
||||
_projection_primary_next_action(
|
||||
gate_code=str((blocking or {}).get('gate_code') or ''),
|
||||
status=str((blocking or {}).get('status') or ''),
|
||||
) if blocking else None
|
||||
# [STEP] 单一裁决:由阻断原因码 / Gate 状态推导业务用户主恢复动作。
|
||||
# 库存 RPA 失败统一下发「重新获取库存」,不再因 worker 责任方被技术动作屏蔽。
|
||||
next_action, technical_auto_only = _resolve_recovery_next_action(
|
||||
blocking=blocking,
|
||||
full=full,
|
||||
execution=execution,
|
||||
)
|
||||
# [STEP] 兼容历史 Gate 行:RPA 失败曾被旧契约错误写成
|
||||
# regenerate_manual_upload_todo;当前 Gate + 原因码才是履约真相,
|
||||
# 统一纠正为用户可主动执行的 RPA 重试。AUTO_UPLOAD 只控制自动触发,
|
||||
# 不参与手动动作投影。
|
||||
blocking_gate_code = str((blocking or {}).get('gate_code') or '').strip().lower()
|
||||
normalized_reason = str(reason_code or '').strip().lower()
|
||||
if (
|
||||
blocking_gate_code == 'freight_upload_rpa'
|
||||
and normalized_reason in {
|
||||
'upload_rpa_failed',
|
||||
'upload_rpa_login_failed',
|
||||
'upload_platform_rejected',
|
||||
}
|
||||
):
|
||||
next_action = 'retry_freight_upload_rpa'
|
||||
elif (
|
||||
blocking_gate_code == 'manual_upload_handoff'
|
||||
and normalized_reason in {'manual_upload_pending', 'upload_result_unknown'}
|
||||
):
|
||||
# 人工交接仍保留人工登记入口(Footer),同时在 Gate 卡提供显式 RPA 重试。
|
||||
next_action = 'retry_freight_upload_rpa'
|
||||
# [STEP] 所有冻结 Gate 动作均可投影到工作台;是否可执行由页面 canHandle
|
||||
# 与 Workspace API 的权限/版本校验共同决定,禁止前端自行派生动作。
|
||||
technical_auto_only = False
|
||||
# 技术责任方的 retry_* 只作为系统执行动作,不能直接充当业务用户主按钮;
|
||||
# RecoveryPlan 仍可在下方投影为经过权限校验的恢复入口。
|
||||
if (
|
||||
next_action
|
||||
and (
|
||||
not is_business_user_action(str(next_action))
|
||||
or (
|
||||
str(full.get('responsible_party') or '').strip().lower() in {'system', 'worker'}
|
||||
and str(next_action).startswith('retry_')
|
||||
)
|
||||
)
|
||||
):
|
||||
next_action = None
|
||||
technical_auto_only = bool(blocking)
|
||||
|
||||
# [STEP] 正式 OT 后的库存阻断仍需给业务用户提供精确入口:技术主动作
|
||||
# (retry_inventory_*)不直接暴露,但 RecoveryPlan 存在时必须保留当前
|
||||
# Gate 的复核入口,否则 apply_post_ot_gate_rules 会把整个阻断误判为系统态,
|
||||
# 前端也就不会挂载 ProcessGateRecoveryCard。
|
||||
if blocking and not next_action:
|
||||
gate_code = str(blocking.get('gate_code') or '').strip().lower()
|
||||
recovery_targets = full.get('recovery_targets') or []
|
||||
if recovery_targets and gate_code == 'inventory_matching':
|
||||
next_action = 'open_inventory_match_review'
|
||||
technical_auto_only = False
|
||||
elif recovery_targets and gate_code == 'inventory_sufficiency':
|
||||
next_action = 'open_shortage_review'
|
||||
technical_auto_only = False
|
||||
|
||||
# 正式 OT 后仍需允许业务用户恢复履约链路中的技术失败:
|
||||
# 库存准备/匹配以及货代上传 RPA 的动作码由 Gate 合同固定,
|
||||
# 不把其他 system/worker 节点泛化为可人工操作。
|
||||
if not next_action and gate_code in {
|
||||
'inventory_preparation',
|
||||
'inventory_matching',
|
||||
'freight_upload_rpa',
|
||||
}:
|
||||
candidate = _projection_primary_next_action(
|
||||
gate_code=gate_code,
|
||||
status=str(blocking.get('status') or ''),
|
||||
)
|
||||
if candidate and is_business_user_action(candidate):
|
||||
next_action = candidate
|
||||
technical_auto_only = False
|
||||
# 无当前阻断时禁止残留 confirm_customer,避免「客户已确认」仍显示为优先处理。
|
||||
if not blocking and str(next_action or '').strip() == 'confirm_customer':
|
||||
next_action = None
|
||||
@@ -513,6 +528,11 @@ def project_user_gate_summary(execution: ShippingProcessExecution) -> dict[str,
|
||||
if blocking:
|
||||
if next_action and is_business_user_action(str(next_action)):
|
||||
allowed_actions.append(str(next_action))
|
||||
if (
|
||||
str(blocking.get('gate_code') or '').strip().lower() == 'inventory_preparation'
|
||||
and next_action == 'retry_inventory_preparation'
|
||||
):
|
||||
allowed_actions.append('upload_inventory_file')
|
||||
for target in full.get('recovery_targets') or []:
|
||||
code = str(target.get('action_code') or '').strip()
|
||||
if code and code not in allowed_actions and is_business_user_action(code):
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.services.shipping_notice.fulfillment_audit import record_fulfillment_au
|
||||
from app.services.shipping_notice.process_gate_contract import (
|
||||
PROCESS_GATE_ACTION_CODES,
|
||||
get_process_gate_definition,
|
||||
inventory_preparation_primary_action,
|
||||
is_business_user_action,
|
||||
is_technical_gate_party,
|
||||
primary_next_action_for_gate,
|
||||
@@ -217,7 +218,8 @@ def request_gate_action(
|
||||
details={'gate_code': gate.gate_code, 'action_code': action},
|
||||
)
|
||||
|
||||
primary = gate.next_action_code or primary_next_action_for_gate(
|
||||
primary = inventory_preparation_primary_action(gate.status) if gate.gate_code == 'inventory_preparation' else None
|
||||
primary = primary or gate.next_action_code or primary_next_action_for_gate(
|
||||
gate_code=gate.gate_code, status=gate.status,
|
||||
)
|
||||
# [STEP] 兼容历史 Gate 20:用户投影已将人工待办旧动作纠正为显式 RPA
|
||||
@@ -236,6 +238,8 @@ def request_gate_action(
|
||||
'adopt_rule_suggestion',
|
||||
'keep_manual_inventory_decision',
|
||||
}
|
||||
if gate.gate_code == 'inventory_preparation' and primary == 'retry_inventory_preparation':
|
||||
allowed_side.add('upload_inventory_file')
|
||||
if primary and action != primary and action not in allowed_side and recovery_definition is None:
|
||||
raise ValidationError(
|
||||
'Action is not the primary recovery action for this gate',
|
||||
|
||||
@@ -10,6 +10,9 @@ services/shipping_notice/ui_state.py
|
||||
stp_facts、progress_nodes);
|
||||
若存在 ProcessExecution:阻断时清空 action_buttons;非阻断时仅保留
|
||||
download_excel / mark_manual_uploaded / refresh(恢复动作仅由 process_gate 驱动);
|
||||
[兼容] action_buttons 为只读兼容字段:权威可恢复操作入口已统一为
|
||||
process_gate.next_action_code(如 retry_inventory_preparation),本字段仅保留供
|
||||
任务详情 / 聊天状态 / 旧入口消费,禁止再向其新增恢复动作;待确认无活跃消费者后删除。
|
||||
Task 即正式 OT,Gate 摘要必须套用 OT 后规则(系统等待不冒充人工待办);
|
||||
批次 UI 仅作会话上传集合摘要,不作为履约写操作面。
|
||||
"""
|
||||
@@ -631,6 +634,8 @@ def build_task_ui_state(task: ShippingNotice) -> dict[str, Any]:
|
||||
"current_step": current_step,
|
||||
"steps": steps,
|
||||
"summary": summary,
|
||||
# [兼容] action_buttons 为只读兼容字段(见模块 docstring);新 UI 应消费
|
||||
# summary.process_gate.next_action_code,本字段仅作历史消费者过渡,不再扩展。
|
||||
"action_buttons": action_buttons,
|
||||
"process_gate": process_gate,
|
||||
"updated_at": task.updated_at.isoformat() if task.updated_at else None,
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
"""
|
||||
tests/test_shipping_process_gate_recovery_action_contract.py
|
||||
|
||||
用途:锁定 Gate 恢复动作投影「单一裁决」契约——库存 RPA 失败统一下发
|
||||
「重新获取库存」(retry_inventory_preparation),不再因 inventory_preparation
|
||||
Gate 的 responsible_party='worker' 被历史「worker/retry_ 技术动作屏蔽」规则
|
||||
降级为人工上传入口 (upload_inventory_file)。
|
||||
|
||||
依赖:process_gate_projection._resolve_recovery_next_action。
|
||||
逻辑:pure_unit 纯单测(不建 Flask/DB);以阻断原因码 / Gate 状态为输入,
|
||||
断言业务用户主恢复动作 next_action_code 与 technical_auto_only 标志。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.shipping_notice.process_gate_projection import (
|
||||
_resolve_recovery_next_action,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def _mk(blocking: dict, *, primary_next_action_code=None, recovery_targets=None,
|
||||
responsible_party='worker') -> dict:
|
||||
"""构造 _resolve_recovery_next_action 所需的 full / blocking 投影输入。"""
|
||||
full = {
|
||||
'primary_next_action_code': primary_next_action_code,
|
||||
'responsible_party': responsible_party,
|
||||
'recovery_targets': recovery_targets or [],
|
||||
}
|
||||
return full, blocking
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_file_empty_blocked_manual_resolves_to_retry():
|
||||
"""核心回归:inventory_file_empty + blocked_manual 必须下发「重新获取库存」。
|
||||
|
||||
真实任务 SN-20260811-717D2EAD 曾因 Gate 状态被写成 blocked_manual 而投影出
|
||||
upload_inventory_file;原因码 inventory_file_empty 在契约中属 retryable_tech,
|
||||
业务用户应可直接重试而非被迫人工上传。
|
||||
"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_file_empty'},
|
||||
primary_next_action_code='upload_inventory_file',
|
||||
)
|
||||
action, tech_only = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
assert tech_only is False
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
@pytest.mark.parametrize('reason', [
|
||||
'inventory_file_empty',
|
||||
'inventory_preparation_failed',
|
||||
'inventory_rpa_timeout',
|
||||
'inventory_rpa_login_failed',
|
||||
'inventory_rpa_export_failed',
|
||||
'inventory_file_identity_mismatch',
|
||||
'inventory_file_missing',
|
||||
'inventory_rpa_exhausted',
|
||||
])
|
||||
def test_all_inventory_rpa_retry_reasons_expose_retry_action(reason):
|
||||
"""全部库存 RPA 失败原因(无论 blocked_manual / blocked_retryable)均下发「重新获取库存」。"""
|
||||
for status in ('blocked_manual', 'blocked_retryable'):
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': status,
|
||||
'blocking_reason_code': reason},
|
||||
)
|
||||
action, tech_only = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation', (reason, status)
|
||||
assert tech_only is False
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_rpa_exhausted_falls_back_to_manual_upload():
|
||||
"""历史耗尽码仍允许用户手动重新获取库存。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_rpa_exhausted'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_file_missing_falls_back_to_manual_upload():
|
||||
"""缺库存文件时仍优先允许用户手动重新获取库存。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_file_missing'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_freight_upload_rpa_failure_keeps_retry_entry():
|
||||
"""货代上传 RPA 失败保持统一 RPA 重试入口(既有行为不回退)。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'freight_upload_rpa', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'upload_rpa_failed'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_freight_upload_rpa'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_matching_recovery_target_navigates_to_review():
|
||||
"""inventory_matching 有 RecoveryPlan 时保留复核入口(既有兜底不回退)。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_matching', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_failed'},
|
||||
recovery_targets=[{'action_code': 'retry_inventory_matching'}],
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'open_inventory_match_review'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_preparation_retryable_without_reason_uses_contract_action():
|
||||
"""无特定原因码、仅 blocked_retryable 时沿用 Gate 合同默认动作(retry_inventory_preparation)。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_retryable',
|
||||
'blocking_reason_code': None},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_preparation_waiting_keeps_refresh_action():
|
||||
"""RPA 正在执行时只允许刷新进度,不能重复提交获取库存。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'waiting_external',
|
||||
'blocking_reason_code': 'inventory_rpa_queued'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'poll_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_no_blocking_returns_no_action():
|
||||
"""无当前阻断时不下发给任何主恢复动作。"""
|
||||
full, _ = _mk({'gate_code': 'inventory_preparation', 'status': 'passed'})
|
||||
action, _ = _resolve_recovery_next_action(blocking=None, full=full, execution=None)
|
||||
assert action is None
|
||||
@@ -348,9 +348,10 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
gate.next_action_code = 'retry_inventory_preparation'
|
||||
db.session.commit()
|
||||
|
||||
captured_payload = {}
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
lambda payload: {
|
||||
lambda payload: captured_payload.update(payload) or {
|
||||
'status': 'success',
|
||||
'data': {
|
||||
'rpa': {
|
||||
@@ -380,6 +381,7 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
task_id=task.id, execution_id=execution.id, gate_attempt_id=attempt.id,
|
||||
).one()
|
||||
assert result.get('skipped') is False
|
||||
assert captured_payload['mode'] == 'retry_rpa'
|
||||
assert attempt.status == 'succeeded'
|
||||
assert gate.status == 'passed'
|
||||
assert preparation.status == 'succeeded'
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
| 10 | `inventory_source_routing` | 库存源路由 | owner | `retry_with_latest_rules` / `open_inventory_source_review` |
|
||||
| 11 | `order_freeze_readiness` | 订单冻结资格 | system | `recheck_freeze_readiness` / `open_order_review` |
|
||||
| 12 | `task_creation` | ShippingTask 创建 | system | `retry_task_creation` |
|
||||
| 13 | `inventory_preparation` | 库存文件或快照准备 | worker | `retry_inventory_preparation` / `poll_inventory_preparation` / `upload_inventory_file` |
|
||||
| 13 | `inventory_preparation` | 库存文件或快照准备 | worker | 运行中 `poll_inventory_preparation`;未通过时主动作 `retry_inventory_preparation`,并保留 `upload_inventory_file` 作为辅助输入入口 |
|
||||
| 14 | `inventory_field_mapping` | 库存字段映射 | owner | `retry_inventory_field_mapping` / `confirm_inventory_field_mapping` |
|
||||
| 15 | `inventory_matching` | Reservation + 料号匹配 | worker | `retry_inventory_matching` / `open_inventory_match_review` |
|
||||
| 16 | `inventory_sufficiency` | 库存满足性 | owner | `recheck_inventory_sufficiency` / `open_shortage_review` |
|
||||
|
||||
@@ -3776,6 +3776,7 @@ watch(
|
||||
:summary="displayCase.process_gate"
|
||||
:can-handle="workbenchActionsExecutable"
|
||||
:navigation-context="reviewGateNavigationContext"
|
||||
inventory-upload-mode="local"
|
||||
:field-labels="reviewFieldLabels"
|
||||
@refreshed="reloadLatestDraft"
|
||||
@refresh-needed="reloadLatestDraft"
|
||||
|
||||
+48
@@ -166,4 +166,52 @@ describe('ProcessGateRecoveryCard', () => {
|
||||
expect(wrapper.find('[data-testid="process-gate-recovery-targets"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="process-gate-recovery-primary"]').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('shows inventory upload as a secondary entry beside retrying inventory retrieval', async () => {
|
||||
const wrapper = mount(ProcessGateRecoveryCard, {
|
||||
props: {
|
||||
summary: baseSummary({
|
||||
current_blocking_gate: {
|
||||
...baseSummary().current_blocking_gate!,
|
||||
gate_code: 'inventory_preparation',
|
||||
next_action_code: 'retry_inventory_preparation',
|
||||
},
|
||||
next_action_code: 'retry_inventory_preparation',
|
||||
allowed_actions: ['retry_inventory_preparation', 'upload_inventory_file'],
|
||||
task_no: 'SN-TEST-001',
|
||||
}),
|
||||
canHandle: true,
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
|
||||
const upload = wrapper.get('[data-testid="process-gate-inventory-upload"]');
|
||||
expect(upload.text()).toContain('上传库存文件');
|
||||
await upload.trigger('click');
|
||||
expect(wrapper.emitted('navigate')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('opens local upload registration when requested by the order review workbench', async () => {
|
||||
const wrapper = mount(ProcessGateRecoveryCard, {
|
||||
props: {
|
||||
summary: baseSummary({
|
||||
current_blocking_gate: {
|
||||
...baseSummary().current_blocking_gate!,
|
||||
gate_code: 'inventory_preparation',
|
||||
next_action_code: 'retry_inventory_preparation',
|
||||
},
|
||||
next_action_code: 'retry_inventory_preparation',
|
||||
allowed_actions: ['retry_inventory_preparation', 'upload_inventory_file'],
|
||||
task_no: 'SN-TEST-001',
|
||||
}),
|
||||
canHandle: true,
|
||||
inventoryUploadMode: 'local',
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
|
||||
await wrapper.get('[data-testid="process-gate-inventory-upload"]').trigger('click');
|
||||
expect(wrapper.emitted('manualUpload')).toHaveLength(1);
|
||||
expect(wrapper.emitted('navigate')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -22,6 +22,8 @@ const props = defineProps<{
|
||||
summary: ShippingProcessGateUserSummary | null | undefined;
|
||||
canHandle: boolean;
|
||||
navigationContext?: ProcessGateNavigationContext;
|
||||
/** 复核工作台直接打开人工上传登记;任务中心默认仍导航到任务详情。 */
|
||||
inventoryUploadMode?: 'navigate' | 'local';
|
||||
/** 复核 Schema 的 field_code/field_id 到业务字段名映射。 */
|
||||
fieldLabels?: Record<string, string>;
|
||||
}>();
|
||||
@@ -47,6 +49,11 @@ const showManualUploadAction = computed(() => (
|
||||
String(blockingGate.value?.gate_code || '').trim().toLowerCase() === 'manual_upload_handoff'
|
||||
&& nextActionCode.value === 'retry_freight_upload_rpa'
|
||||
));
|
||||
const showInventoryUploadAction = computed(() => (
|
||||
String(blockingGate.value?.gate_code || '').trim().toLowerCase() === 'inventory_preparation'
|
||||
&& nextActionCode.value === 'retry_inventory_preparation'
|
||||
&& (props.summary?.allowed_actions || []).includes('upload_inventory_file')
|
||||
));
|
||||
|
||||
/**
|
||||
* 是否对业务用户展示「待处理事项」。
|
||||
@@ -142,6 +149,19 @@ async function runPrimaryAction() {
|
||||
}
|
||||
}
|
||||
|
||||
async function runInventoryUpload() {
|
||||
if (!props.summary || !props.canHandle || busy.value) return;
|
||||
if (props.inventoryUploadMode === 'local') {
|
||||
emit('manualUpload');
|
||||
return;
|
||||
}
|
||||
const result = await submitPrimaryAction(props.summary, {
|
||||
actionCode: 'upload_inventory_file',
|
||||
navigationContext: props.navigationContext,
|
||||
});
|
||||
if (result.outcome === 'navigated') emit('navigate');
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -182,6 +202,15 @@ async function runPrimaryAction() {
|
||||
>
|
||||
{{ busy ? $t('workspace.shippingNotice.processGate.submitting') : actionLabel }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showInventoryUploadAction && canHandle"
|
||||
type="button"
|
||||
class="inline-flex min-h-8 items-center rounded-md border border-default bg-surface px-3 py-1.5 text-xs font-semibold text-secondary shadow-sm transition hover:bg-surface-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500 focus-visible:ring-offset-2"
|
||||
data-testid="process-gate-inventory-upload"
|
||||
@click="runInventoryUpload"
|
||||
>
|
||||
{{ $t('workspace.shippingNotice.processGate.actionCodes.upload_inventory_file') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showManualUploadAction && canHandle"
|
||||
type="button"
|
||||
|
||||
+2
-1
@@ -116,7 +116,8 @@ export function useShippingProcessGateRecovery() {
|
||||
const requestedAction = String(options?.actionCode || '').trim();
|
||||
const serverRecoveryAction = (summary.recovery_targets || [])
|
||||
.find((target) => String(target.action_code || '').trim() === requestedAction)
|
||||
?.action_code;
|
||||
?.action_code
|
||||
|| (summary.allowed_actions || []).find((code) => String(code).trim() === requestedAction);
|
||||
if (requestedAction && !serverRecoveryAction) {
|
||||
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
||||
return { outcome: 'noop' };
|
||||
|
||||
Reference in new issue
Block a user