feat(shipping-notice): 优化货运订单履约流程与用户体验
- 优化聊天附件列表为横向可滚动布局并新增配套测试用例 - 移除自动填充默认用户消息逻辑,空备注时不再伪造默认正文 - 修复流程Gate动作展示逻辑,隐藏历史遗留操作与自动阶段无效按钮 - 完善库存匹配重试与订单快照冻结校验流程 - 优化进度展示优先级,优先显示人工待处理状态 - 移除Excel导出自动推导金额逻辑,强制使用Schema配置字段 - 新增货代通用报表RPA详细设计文档 - 更新相关测试用例与断言逻辑
This commit is contained in:
1 parent
dc282f3b1d
commit
11cef575b4
51 files changed
+2197
-112
No files matched your search
@@ -387,8 +387,8 @@ def test_excel_pull_request_number_uses_export_date_without_changing_case_number
|
||||
assert shipping_case.business_no == 'IVMX26080801'
|
||||
|
||||
|
||||
def test_export_mapping_falls_back_to_export_sequence_and_derived_line_amount(app):
|
||||
"""LineNumber 缺失时用导出行序号,Shipment Value 缺失时用数量乘单价。"""
|
||||
def test_export_mapping_uses_sequence_but_never_derives_formal_line_amount(app):
|
||||
"""正式金额必须来自 Schema FieldValue,禁止由快照或单价静默推导。"""
|
||||
with app.app_context():
|
||||
fields = _lookup_standard_fields('line_no', 'line_amount_with_tax')
|
||||
task = ShippingNotice(task_no='TASK-MAPPING')
|
||||
@@ -400,7 +400,7 @@ def test_export_mapping_falls_back_to_export_sequence_and_derived_line_amount(ap
|
||||
assert _mapping_value(
|
||||
{'source_kind': 'order_field', 'source_key': fields['line_amount_with_tax'].id, 'formatter': 'decimal', 'row_mode': 'line'},
|
||||
task=task, order_values={'__qty': Decimal('14'), '__unit_price': Decimal('941.76')}, inventory_values={},
|
||||
) == 13184.64
|
||||
) is None
|
||||
|
||||
|
||||
def test_clear_template_data_rows_keeps_headers_and_removes_residual_values():
|
||||
|
||||
@@ -470,6 +470,32 @@ def test_rpa_report_inventory_batch_mixed_results_exposes_partial_failed(app, tm
|
||||
assert result["failed_count"] == 1
|
||||
|
||||
|
||||
def test_rpa_snapshot_persists_confirmed_profile_mapping(app, tmp_path):
|
||||
"""RPA 文件经过正式 Profile 校验后必须直接确认映射,不进入人工 Gate。"""
|
||||
from app import db
|
||||
from app.models import ShippingInventoryFile
|
||||
from app.services.shipping_notice.inventory_rpa_workflow import rpa_report_inventory_batch
|
||||
|
||||
drop_dir = tmp_path / "drop"
|
||||
drop_dir.mkdir()
|
||||
app.config["SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR"] = str(drop_dir)
|
||||
app.config["SHIPPING_NOTICE_STORAGE_ROOT"] = str(tmp_path / "storage")
|
||||
sample = drop_dir / "inventory-mapping-confirmed.xlsx"
|
||||
sample.write_bytes(inventory_xlsx_with_warehouse("AWSDU").getvalue())
|
||||
|
||||
with app.app_context():
|
||||
result = rpa_report_inventory_batch(_with_v2_batch_envelope({
|
||||
"run_no": "RUN-MAPPING-CONFIRMED",
|
||||
"trigger_type": "scheduled",
|
||||
"results": [scheduled_rpa_batch_item("DSV360_AWSDU", success=True, file_path=str(sample))],
|
||||
}))
|
||||
assert result["success_count"] == 1
|
||||
snapshot = ShippingInventoryFile.query.filter_by(rpa_run_no="RUN-MAPPING-CONFIRMED").one()
|
||||
assert snapshot.mapping_source == "parsing_profile"
|
||||
assert snapshot.mapping_confirmed is True
|
||||
assert snapshot.field_mapping_json
|
||||
|
||||
|
||||
def test_rpa_report_inventory_batch_all_failed_still_returns_ok(app, tmp_path):
|
||||
"""全 failed 时接口 status 仍为 ok,业务结果见 result_status=failed。"""
|
||||
from app.services.shipping_notice.inventory_rpa_workflow import rpa_report_inventory_batch
|
||||
|
||||
@@ -11,11 +11,12 @@ import pytest
|
||||
from app.services.shipping_notice.rpa import write_inventory_export_trigger_for_task
|
||||
|
||||
|
||||
def test_on_demand_uses_batch_trigger_when_enabled(app, tmp_path):
|
||||
def test_on_demand_uses_batch_trigger_when_enabled(app, tmp_path, monkeypatch):
|
||||
"""batch 开启时单票按需应写 inventory_export_batch trigger。"""
|
||||
trigger_dir = tmp_path / "triggers"
|
||||
app.config["SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR"] = str(trigger_dir)
|
||||
app.config["SHIPPING_NOTICE_INVENTORY_RPA_BATCH_ENABLED"] = True
|
||||
app.config.pop("SHIPPING_NOTICE_INVENTORY_RPA_BATCH_ENABLED", None)
|
||||
monkeypatch.setenv("SHIPPING_NOTICE_INVENTORY_RPA_BATCH_ENABLED", "true")
|
||||
|
||||
source = {
|
||||
"source_code": "DSV360_AWSDU",
|
||||
|
||||
@@ -13,7 +13,7 @@ from datetime import datetime
|
||||
import pytest
|
||||
|
||||
from app import db
|
||||
from app.models import ShippingOrderProcessingRun
|
||||
from app.models import ChatSession, ShippingOrderProcessingRun
|
||||
from app.services.shipping_notice.order_extraction_run_service import (
|
||||
create_order_extraction_run,
|
||||
evaluate_can_append,
|
||||
@@ -167,6 +167,35 @@ def test_submit_idempotent_by_submission_id(app):
|
||||
assert ShippingOrderProcessingRun.query.count() == 1
|
||||
|
||||
|
||||
def test_submit_multiple_unbound_intakes_creates_one_chat_session(app):
|
||||
"""一次多邮件首次提交可建多个 Run,但必须共用服务端新建的一个会话。"""
|
||||
with app.app_context():
|
||||
user, agent, _session, first_intake, _document = _seed_run_input(suffix='MULTI-EML-A')
|
||||
_, _, _, second_intake, _document = _seed_run_input(
|
||||
suffix='MULTI-EML-B',
|
||||
agent_code='shipping_notice_multi_eml_b',
|
||||
)
|
||||
first_intake.conversation_id = None
|
||||
second_intake.user_id = user.id
|
||||
second_intake.conversation_id = None
|
||||
db.session.commit()
|
||||
|
||||
payload = submit_order_extraction(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id='',
|
||||
intake_nos=[first_intake.intake_no, second_intake.intake_no],
|
||||
submission_id='SUB-TEST-MULTI-EML-ONE-CONVERSATION',
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
runs = ShippingOrderProcessingRun.query.order_by(ShippingOrderProcessingRun.id).all()
|
||||
conversation_ids = {run.conversation_id for run in runs}
|
||||
assert len(runs) == 2
|
||||
assert conversation_ids == {runs[0].conversation_id}
|
||||
assert ChatSession.query.filter(ChatSession.session_id.in_(conversation_ids)).count() == 1
|
||||
|
||||
|
||||
def test_legacy_create_can_still_block_parallel_when_flag_false(app):
|
||||
"""兼容路径 allow_parallel_conversation_runs=False 仍抛 CONVERSATION_ACTIVE。"""
|
||||
with app.app_context():
|
||||
|
||||
@@ -978,6 +978,8 @@ def test_confirm_review_case_creates_one_task_and_immutable_revision(app):
|
||||
assert getattr(task, 'order_task_id', None) is not None
|
||||
assert task.source_candidate_id is not None
|
||||
assert task.current_order_extraction_id is not None
|
||||
# 关键断言:复核确认建单必须同步冻结,库存/RPA 不可消费可变解析结果。
|
||||
assert task.order_snapshot_id is not None
|
||||
# 关键断言:复核确认已完成解析确认,不能把新任务重新放回低置信度解析复核。
|
||||
assert task.process_status == 'parsed'
|
||||
assert task.review_status is None
|
||||
|
||||
@@ -197,6 +197,49 @@ def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technica
|
||||
]
|
||||
|
||||
|
||||
def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch):
|
||||
"""正式 OT 库存匹配阻断不得投影无写操作的复核入口。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-INV-OT-1', status='blocked',
|
||||
current_gate_code='inventory_matching', primary_next_action_code='open_inventory_match_review',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=99,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
projection,
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-INV-OT-1', 'status': 'blocked',
|
||||
'primary_next_action_code': 'open_inventory_match_review',
|
||||
'responsible_party': 'worker',
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_matching',
|
||||
'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_incomplete',
|
||||
'next_action_code': 'open_inventory_match_review',
|
||||
},
|
||||
'recovery_targets': [
|
||||
{'action_code': 'open_inventory_match_review', 'target_gate': 'inventory_matching'},
|
||||
{'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'},
|
||||
],
|
||||
'gates': [], 'active_recovery_plans': [],
|
||||
},
|
||||
)
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['next_action_code'] == 'retry_inventory_matching'
|
||||
assert summary['allowed_actions'] == [
|
||||
'retry_inventory_matching',
|
||||
'retry_inventory_from_preparation',
|
||||
]
|
||||
assert summary['recovery_targets'] == [
|
||||
{'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'},
|
||||
]
|
||||
|
||||
|
||||
def test_user_gate_summary_exposes_sanitized_failure_detail_for_any_gate(app, monkeypatch):
|
||||
"""所有 Gate 均应把当前 Attempt 的脱敏失败详情投影给用户,而非只显示泛化原因。"""
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -13,11 +13,16 @@ Gate 的 responsible_party='worker' 被历史「worker/retry_ 技术动作屏蔽
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.shipping_notice.process_gate_projection import (
|
||||
_resolve_recovery_next_action,
|
||||
)
|
||||
from app.services.shipping_notice.process_gate_recovery_service import (
|
||||
_primary_recovery_action,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
@@ -118,6 +123,51 @@ def test_inventory_matching_recovery_target_navigates_to_review():
|
||||
assert action == 'open_inventory_match_review'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_formal_inventory_matching_recovery_target_retries_matching():
|
||||
"""正式 OT 的库存匹配阻断必须下发可执行的重新库存匹配。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_matching', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_failed'},
|
||||
recovery_targets=[{'action_code': 'retry_inventory_from_preparation'}],
|
||||
)
|
||||
action, tech_only = _resolve_recovery_next_action(
|
||||
blocking=blocking,
|
||||
full=full,
|
||||
execution=SimpleNamespace(task_id=99),
|
||||
)
|
||||
assert action == 'retry_inventory_matching'
|
||||
assert tech_only is False
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_formal_inventory_matching_request_validation_uses_retry_action():
|
||||
"""正式 OT 的请求校验必须与用户投影一致,覆盖旧导航动作。"""
|
||||
action = _primary_recovery_action(
|
||||
execution=SimpleNamespace(task_id=99),
|
||||
gate=SimpleNamespace(
|
||||
gate_code='inventory_matching',
|
||||
status='blocked_manual',
|
||||
next_action_code='open_inventory_match_review',
|
||||
),
|
||||
)
|
||||
assert action == 'retry_inventory_matching'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_matching_retryable_exposes_retry_action():
|
||||
"""库存匹配 Gate 可重试时必须直接显示重新匹配按钮。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_matching', 'status': 'blocked_retryable',
|
||||
'blocking_reason_code': 'inventory_match_failed'},
|
||||
)
|
||||
action, technical_auto_only = _resolve_recovery_next_action(
|
||||
blocking=blocking, full=full, execution=None,
|
||||
)
|
||||
assert action == 'retry_inventory_matching'
|
||||
assert technical_auto_only is False
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_preparation_retryable_without_reason_uses_contract_action():
|
||||
"""无特定原因码、仅 blocked_retryable 时沿用 Gate 合同默认动作(retry_inventory_preparation)。"""
|
||||
|
||||
@@ -114,6 +114,77 @@ def test_preparation_trigger_identity_includes_gate_and_callback(monkeypatch, ap
|
||||
assert captured['callback_id'].endswith(':C1')
|
||||
|
||||
|
||||
def test_missing_inventory_trigger_is_failed_not_pending(monkeypatch, app):
|
||||
"""trigger 写入返回空路径时,Attempt 必须失败,禁止伪装 queued。"""
|
||||
from app import db
|
||||
from app.models import ShippingNotice
|
||||
from app.services.shipping_notice import per_source_rpa_service
|
||||
|
||||
task = ShippingNotice(task_no='SN-PREP-TRIGGER-MISSING', process_status='waiting_inventory')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
monkeypatch.setattr(per_source_rpa_service, 'task_frozen_inventory_source_codes', lambda task: ['DBS'])
|
||||
monkeypatch.setattr(per_source_rpa_service, '_snapshot_ready_for_source', lambda *args, **kwargs: False)
|
||||
monkeypatch.setattr(per_source_rpa_service, '_latest_attempt', lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(per_source_rpa_service, 'write_inventory_export_trigger_for_task', lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_source_repository.get_database_inventory_source',
|
||||
lambda code: {'source_code': code, 'warehouse_id': 'WH-1'},
|
||||
)
|
||||
result = per_source_rpa_service.ensure_all_required_sources_prepared(task, mode='retry_rpa')
|
||||
assert result.pending_source_codes == []
|
||||
assert result.failed_source_codes == ['DBS']
|
||||
attempt = per_source_rpa_service._latest_attempt(task.task_no, 'DBS')
|
||||
assert attempt.status == 'failed'
|
||||
assert attempt.error_code == 'trigger_not_written'
|
||||
|
||||
|
||||
def test_formal_gate_inventory_retry_uses_operator_id_for_snapshot_freeze(monkeypatch, app):
|
||||
"""正式 Gate Worker 仅携带 operator_id 时,也必须先冻结快照再写 RPA trigger。"""
|
||||
from app import db
|
||||
from app.models import ShippingNotice, ShippingProcessExecution
|
||||
from app.services.shipping_notice import process_gate_executor
|
||||
|
||||
task = ShippingNotice(
|
||||
task_no='SN-PREP-FREEZE-OPERATOR', process_status='waiting_inventory',
|
||||
order_snapshot_id=None, order_data_version=1,
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-PREP-FREEZE-OPERATOR', task_id=task.id,
|
||||
current_gate_code='inventory_preparation', status='blocked',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
|
||||
seen = {}
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.order_freeze_service.freeze_order_snapshot',
|
||||
lambda task, **kwargs: seen.update(kwargs) or object(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_recovery_service.create_inventory_preparation_round',
|
||||
lambda **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
lambda payload: {'status': 'running', 'data': {'rpa': {}}},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_bridge.sync_fulfillment_gates_from_task',
|
||||
lambda **kwargs: None,
|
||||
)
|
||||
|
||||
gate = type('Gate', (), {'gate_code': 'inventory_preparation', 'status': 'blocked_manual', 'blocking_reason_code': None})()
|
||||
result = process_gate_executor._handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={'action_code': 'retry_inventory_preparation', 'operator_id': 77},
|
||||
)
|
||||
assert seen['actor_id'] == 77
|
||||
assert result['outcome'] in {'blocked_retryable', 'blocked_manual'}
|
||||
|
||||
|
||||
def test_per_source_callback_rejects_candidate_set_identity_mismatch(app):
|
||||
"""旧 CandidateSet 回调必须在写入库存事实前被拒绝。"""
|
||||
from app import db
|
||||
@@ -308,6 +379,78 @@ def test_rpa_report_inventory_batch_fails_closed_on_per_source_identity_mismatch
|
||||
).count() == 1
|
||||
|
||||
|
||||
def test_batch_callback_inherits_authenticated_top_level_schema_version():
|
||||
"""Worker 将 schema_version 放在 batch 顶层时,结果项仍须通过逐源身份校验。"""
|
||||
from app.services.shipping_notice.inventory_rpa_workflow import _merge_batch_callback_item
|
||||
|
||||
merged = _merge_batch_callback_item(
|
||||
{
|
||||
'schema_version': 'shipping_inventory_rpa.v2',
|
||||
'run_no': 'BATCH-1',
|
||||
'task_no': 'SN-1',
|
||||
},
|
||||
{
|
||||
'source_code': 'DSV360_AWSSG',
|
||||
'source_run_no': 'PSR-SN-1-DSV360_AWSSG-A1-ABC',
|
||||
},
|
||||
)
|
||||
|
||||
assert merged['schema_version'] == 'shipping_inventory_rpa.v2'
|
||||
assert merged['run_no'] == 'BATCH-1'
|
||||
assert merged['task_no'] == 'SN-1'
|
||||
|
||||
|
||||
def test_inventory_rpa_failure_is_not_projected_back_to_waiting_external(app):
|
||||
"""RPA 已耗尽时自动轮询必须终态化,Gate 才能退出系统处理中。"""
|
||||
from app import db
|
||||
from app.models import ShippingNotice, ShippingProcessExecution, ShippingProcessGate, ShippingProcessGateAttempt
|
||||
from app.services.shipping_notice.process_gate_bridge import sync_fulfillment_gates_from_task
|
||||
from app.services.shipping_notice.process_gate_service import queue_gate_attempt
|
||||
|
||||
task = ShippingNotice(
|
||||
task_no='SN-RPA-FAILED-GATE', process_status='waiting_inventory',
|
||||
pending_human_reason='rpa_exhausted', error_message='RPA export failed',
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-RPA-FAILED-GATE', task_id=task.id, status='waiting_external',
|
||||
current_gate_code='inventory_preparation',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
|
||||
sync_fulfillment_gates_from_task(execution=execution)
|
||||
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id, gate_code='inventory_preparation',
|
||||
).one()
|
||||
auto_poll = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
trigger_type='auto',
|
||||
actor_type='system',
|
||||
idempotency_key='shipping-auto-progress:rpa-failed-poll',
|
||||
input_snapshot={'action_code': 'poll_inventory_preparation'},
|
||||
)
|
||||
db.session.flush()
|
||||
|
||||
sync_fulfillment_gates_from_task(execution=execution)
|
||||
|
||||
db.session.refresh(auto_poll)
|
||||
db.session.refresh(gate)
|
||||
assert auto_poll.status == 'superseded'
|
||||
assert auto_poll.error_code == 'rpa_callback_failed'
|
||||
assert ShippingProcessGateAttempt.query.filter(
|
||||
ShippingProcessGateAttempt.gate_id == gate.id,
|
||||
ShippingProcessGateAttempt.status.in_(('queued', 'running')),
|
||||
).count() == 0
|
||||
assert gate.status == 'blocked_manual'
|
||||
assert gate.blocking_reason_code == 'inventory_rpa_exhausted'
|
||||
db.session.refresh(execution)
|
||||
assert execution.status == 'blocked'
|
||||
|
||||
|
||||
def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, monkeypatch):
|
||||
"""正式库存准备 Gate 执行必须创建 Preparation/Source lineage 并据此通过 Gate。"""
|
||||
from app import db
|
||||
@@ -749,6 +892,67 @@ def test_gate_executor_task_payload_uses_internal_orchestrator_dispatch(monkeypa
|
||||
assert result['operator_id'] == 9
|
||||
|
||||
|
||||
def test_inventory_preparation_retry_freezes_legacy_task_before_rpa(monkeypatch):
|
||||
"""旧 Task 缺订单快照时,Gate 重试必须先冻结,不能再次返回快照缺失。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice.process_gate_executor import _handle_retry_inventory_preparation
|
||||
|
||||
task = SimpleNamespace(
|
||||
order_snapshot_id=None,
|
||||
order_data_version=7,
|
||||
task_no='SN-LEGACY-SNAPSHOT-1',
|
||||
)
|
||||
captured = {}
|
||||
monkeypatch.setattr(
|
||||
'app.models.ShippingNotice.query',
|
||||
SimpleNamespace(get=lambda _task_id: task),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_executor.db.session.flush',
|
||||
lambda: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.order_freeze_service.freeze_order_snapshot',
|
||||
lambda target, **kwargs: captured.update(target=target, **kwargs) or setattr(target, 'order_snapshot_id', 901),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_recovery_service.create_inventory_preparation_round',
|
||||
lambda **_: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
lambda _payload: {'status': 'running', 'message': 'waiting RPA'},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_bridge.inventory_preparation_reason_code',
|
||||
lambda _task: 'inventory_preparation_failed',
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_bridge.sync_fulfillment_gates_from_task',
|
||||
lambda **_: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_executor._task_payload',
|
||||
lambda _execution, _payload: {'task_id': task.task_no},
|
||||
)
|
||||
|
||||
result = _handle_retry_inventory_preparation(
|
||||
execution=SimpleNamespace(task_id=13, id=21),
|
||||
gate=SimpleNamespace(gate_code='inventory_preparation'),
|
||||
payload={'action_code': 'retry_inventory_preparation', 'actor_user_id': 5},
|
||||
)
|
||||
|
||||
# 关键断言:正式 Gate 入口也补冻结,后续才允许进入库存 RPA。
|
||||
assert captured == {
|
||||
'target': task,
|
||||
'actor_id': 5,
|
||||
'expected_order_data_version': 7,
|
||||
'freeze_mode': 'manual',
|
||||
}
|
||||
assert task.order_snapshot_id == 901
|
||||
assert result['outcome'] == 'waiting_external'
|
||||
|
||||
|
||||
def test_manual_business_block_is_a_successful_attempt(app):
|
||||
"""库存匹配已执行但存在缺口时,Attempt 成功、Gate 保持人工阻断。"""
|
||||
from app import db
|
||||
|
||||
@@ -429,3 +429,58 @@ def test_project_user_gate_summary_clears_stale_confirm_customer(monkeypatch):
|
||||
summary = project_user_gate_summary(execution)
|
||||
assert summary['current_blocking_gate'] is None
|
||||
assert summary['next_action_code'] is None
|
||||
|
||||
|
||||
def test_project_user_gate_summary_exposes_retry_for_confirmed_inventory_pending_match(monkeypatch):
|
||||
"""已确认库存快照而匹配仍 pending 时,必须给精确重匹配按钮。"""
|
||||
execution = SimpleNamespace(execution_no='EX-MATCH-1', id=1, task_id=9, current_gate_code='inventory_matching')
|
||||
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_projection.serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EX-MATCH-1', 'status': 'running', 'primary_next_action_code': None,
|
||||
'responsible_party': 'worker', 'gates': [],
|
||||
'current_gate': {'gate_code': 'inventory_matching', 'status': 'pending', 'blocking_reason_code': None},
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_projection._has_confirmed_inventory_for_matching',
|
||||
lambda _execution: True,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_projection._execution_navigation_refs',
|
||||
lambda _execution: {'case_no': 'SORC-1', 'review_case_no': 'SORC-1', 'review_run_no': 'RUN-1', 'task_no': 'SN-1'},
|
||||
)
|
||||
|
||||
summary = project_user_gate_summary(execution)
|
||||
|
||||
assert summary['current_blocking_gate']['status'] == 'blocked_retryable'
|
||||
assert summary['next_action_code'] == 'retry_inventory_matching'
|
||||
assert summary['allowed_actions'] == ['retry_inventory_matching']
|
||||
|
||||
|
||||
def test_project_user_gate_summary_keeps_pending_match_system_owned_without_inventory(monkeypatch):
|
||||
"""没有确认库存时不得伪造重匹配入口。"""
|
||||
execution = SimpleNamespace(execution_no='EX-MATCH-2', id=2, task_id=10, current_gate_code='inventory_matching')
|
||||
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_projection.serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EX-MATCH-2', 'status': 'running', 'primary_next_action_code': None,
|
||||
'responsible_party': 'worker', 'gates': [],
|
||||
'current_gate': {'gate_code': 'inventory_matching', 'status': 'pending', 'blocking_reason_code': None},
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_projection._has_confirmed_inventory_for_matching',
|
||||
lambda _execution: False,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_projection._execution_navigation_refs',
|
||||
lambda _execution: {'case_no': None, 'review_case_no': None, 'review_run_no': None, 'task_no': 'SN-2'},
|
||||
)
|
||||
|
||||
summary = project_user_gate_summary(execution)
|
||||
|
||||
assert summary['current_blocking_gate'] is None
|
||||
assert summary['next_action_code'] is None
|
||||
@@ -17,6 +17,41 @@ from app.services.shipping_notice.stp_line_inventory_match import (
|
||||
)
|
||||
|
||||
|
||||
def test_current_match_facts_rebuild_shortage_detail(monkeypatch):
|
||||
"""当前行事实有缺口时,工作台详情必须拿到数量和 shortage 状态。"""
|
||||
from app.services.shipping_notice import fulfillment_workflow as mod
|
||||
|
||||
rows = [
|
||||
SimpleNamespace(
|
||||
line_index=0, line_key='line-1', match_result='matched',
|
||||
part_number='PN-1', reservation_id='R1', unit='EA',
|
||||
inventory_source_code='SRC', required_qty=3, available_qty=3,
|
||||
shortage_qty=0,
|
||||
),
|
||||
SimpleNamespace(
|
||||
line_index=1, line_key='line-2', match_result='not_found',
|
||||
part_number='PN-2', reservation_id='R2', unit='EA',
|
||||
inventory_source_code='SRC', required_qty=5, available_qty=0,
|
||||
shortage_qty=5,
|
||||
),
|
||||
]
|
||||
fake_match_model = SimpleNamespace(
|
||||
query=SimpleNamespace(
|
||||
filter_by=lambda **_kwargs: SimpleNamespace(all=lambda: rows),
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(mod, 'ShippingNoticeLineInventoryMatch', fake_match_model)
|
||||
task = SimpleNamespace(id=101, line_results_json=None, shortage_json=None)
|
||||
|
||||
status, shortages = mod._recompute_task_match_aggregate(task)
|
||||
|
||||
assert status == 'partial'
|
||||
assert task.line_results_json[1]['available_qty'] == 0.0
|
||||
assert task.line_results_json[1]['shortage_qty'] == 5.0
|
||||
assert task.line_results_json[1]['line_status'] == 'shortage'
|
||||
assert task.shortage_json == {'lines': shortages}
|
||||
|
||||
|
||||
def test_cross_candidate_unique_hit_is_fulfillable():
|
||||
"""唯一候选文件命中且数量充足 → fulfillable 并冻结源。"""
|
||||
result = match_order_lines_across_candidates(
|
||||
|
||||
Reference in new issue
Block a user