feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
1 parent
7cfd5d167e
commit
1e5aedb9ed
235 files changed
+11394
-9613
No files matched your search
@@ -1082,71 +1082,48 @@ def test_current_inventory_rematch_shortage_completes_recovery_plan():
|
||||
assert plan.completed_at is not None
|
||||
|
||||
|
||||
def test_excel_regeneration_completion_preserves_manual_upload_gate():
|
||||
"""跨 Gate Excel 重生完成后,当前 Gate 20 必须继续等待人工上传且计划可关闭。"""
|
||||
from app.services.shipping_notice.recovery_plan_service import complete_recovery_plan_for_attempt
|
||||
|
||||
class Plan:
|
||||
status = 'queued'
|
||||
action_code = 'regenerate_excel_artifact'
|
||||
resume_after_gate = 'manual_upload_handoff'
|
||||
started_at = None
|
||||
completed_at = None
|
||||
failure_code = None
|
||||
failure_detail_json = None
|
||||
|
||||
plan = Plan()
|
||||
complete_recovery_plan_for_attempt(
|
||||
plan=plan,
|
||||
outcome='blocked_manual',
|
||||
business_result_code='manual_upload_pending',
|
||||
)
|
||||
|
||||
assert plan.status == 'succeeded'
|
||||
assert plan.completed_at is not None
|
||||
|
||||
|
||||
def test_manual_upload_excel_regeneration_returns_to_manual_handoff(monkeypatch):
|
||||
"""Gate 20 触发 Excel 重生后,执行器必须作废旧产物并保持人工上传阻断。"""
|
||||
def test_excel_regeneration_rejects_existing_notice_artifact(monkeypatch):
|
||||
"""已有 Excel 时不能在同一 Notice 重生,必须创建新的 Notice。"""
|
||||
from types import SimpleNamespace
|
||||
from app.models import ShippingExportArtifact, ShippingNotice
|
||||
from app.services.shipping_notice.process_gate_executor import _handle_regenerate_excel
|
||||
|
||||
invalidated = {}
|
||||
task = SimpleNamespace(id=1, task_no='SN-ONE-EXCEL')
|
||||
monkeypatch.setattr(ShippingNotice, 'query', SimpleNamespace(get=lambda _id: task))
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.recovery_invalidation_service.invalidate_excel_regeneration_only',
|
||||
lambda **kwargs: invalidated.update(kwargs) or {'artifacts': [10], 'uploads': [11]},
|
||||
ShippingExportArtifact,
|
||||
'query',
|
||||
SimpleNamespace(filter_by=lambda **_kwargs: SimpleNamespace(first=lambda: SimpleNamespace(id=10))),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.fulfillment_workflow.generate_excel',
|
||||
lambda _payload: {'status': 'ok'},
|
||||
)
|
||||
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: {'_orchestrator_internal_dispatch': True},
|
||||
lambda _payload: pytest.fail('existing Artifact must not be regenerated'),
|
||||
)
|
||||
|
||||
outcome = _handle_regenerate_excel(
|
||||
execution=SimpleNamespace(execution_no='SPE-EXCEL-HANDOFF', task_id=1),
|
||||
gate=SimpleNamespace(gate_code='manual_upload_handoff'),
|
||||
payload={'attempt_id': 3, 'actor_user_id': 9},
|
||||
payload={'actor_user_id': 9},
|
||||
)
|
||||
|
||||
assert invalidated['attempt_id'] == 3
|
||||
assert outcome['outcome'] == 'blocked_manual'
|
||||
assert outcome['blocking_reason_code'] == 'manual_upload_pending'
|
||||
assert outcome['output_snapshot']['invalidation']['artifacts'] == [10]
|
||||
assert outcome['blocking_reason_code'] == 'notice_excel_already_generated'
|
||||
|
||||
|
||||
def test_artifact_excel_regeneration_failure_resyncs_artifact_gate(monkeypatch):
|
||||
"""Excel 生成失败后必须重投影 artifact Gate,不能沿用上传阶段。"""
|
||||
from types import SimpleNamespace
|
||||
from app.models import ShippingExportArtifact, ShippingNotice
|
||||
from app.services.shipping_notice.process_gate_executor import _handle_regenerate_excel
|
||||
|
||||
synced = []
|
||||
task = SimpleNamespace(id=1, task_no='SN-FIRST-EXCEL')
|
||||
monkeypatch.setattr(ShippingNotice, 'query', SimpleNamespace(get=lambda _id: task))
|
||||
monkeypatch.setattr(
|
||||
ShippingExportArtifact,
|
||||
'query',
|
||||
SimpleNamespace(filter_by=lambda **_kwargs: SimpleNamespace(first=lambda: None)),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.fulfillment_workflow.generate_excel',
|
||||
lambda _payload: {'status': 'failed', 'message': 'template unavailable'},
|
||||
|
||||
Reference in new issue
Block a user