feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程

清理废弃的shipping xfa ocr automark相关代码和job配置
新增收料报表管理的前端页面、路由和侧边栏入口
新增后端收料报表配置接口、数据库模型和RPA脚本
优化发货通知流程的重试策略,将shipping相关job默认不自动重试
移除废弃的库存源确认相关逻辑,更新流程门禁规则
重构订单模板的值适配器模块,新增坐标OCR值适配器
清理前端shipping菜单和action的废弃选项
更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
hugo committed 2026-08-20 20:23:10 +08:00
1 parent 260465b72d
commit 1b6483a4ea
466 files changed
+32115 -33796

No files matched your search

@@ -15,6 +15,7 @@ from app.services.shipping_notice.process_gate_contract import (
PROCESS_GATE_CODE_SET,
PROCESS_GATE_DEFINITIONS,
PROCESS_GATE_REASON_OWNING_GATE,
action_belongs_to_gate,
assert_process_gate_contract_integrity,
action_presentation,
field_quality_may_block,
@@ -58,6 +59,27 @@ def test_inventory_source_routing_primary_retry_action():
status='blocked_retryable',
)
assert action == 'retry_with_latest_rules'
assert primary_next_action_for_gate(
gate_code='inventory_source_routing', status='blocked_manual',
) == 'retry_with_latest_rules'
assert action_belongs_to_gate(
gate_code='inventory_source_routing', action_code='open_inventory_source_review',
) is False
assert action_belongs_to_gate(
gate_code='inventory_field_mapping', action_code='confirm_inventory_field_mapping',
) is False
def test_gate_action_contract_rejects_inventory_reroute_for_excel_gate():
"""库存源重路由动作绝不能被 Excel Gate 自动入队。"""
assert action_belongs_to_gate(
gate_code='excel_readiness',
action_code='retry_with_latest_rules',
) is False
assert action_belongs_to_gate(
gate_code='excel_readiness',
action_code='recheck_excel_readiness',
) is True
def test_inventory_sufficiency_actions_keep_business_specific_labels():
@@ -67,6 +89,7 @@ def test_inventory_sufficiency_actions_keep_business_specific_labels():
'label_key': 'workspace.shippingNotice.processGate.actionCodes.open_shortage_review',
'kind': 'current_gate',
'dispatch': 'navigation',
'ui_handler': 'shortage_review',
}
assert action_presentation('retry_inventory_from_matching') == {
'code': 'retry_inventory_from_matching',
@@ -76,6 +99,70 @@ def test_inventory_sufficiency_actions_keep_business_specific_labels():
}
def test_fulfillment_action_presentation_declares_lifecycle_surface():
"""动作位置必须继承当前 Gate,而非维护 action_code 到位置的映射。"""
assert action_presentation(
'regenerate_excel_artifact', gate_code='artifact_generation',
)['target_surface'] == 'fulfillment_prep'
assert action_presentation(
'retry_freight_upload_rpa', gate_code='freight_upload_rpa',
)['target_surface'] == 'upload_complete'
assert action_presentation(
'regenerate_manual_upload_todo', gate_code='manual_upload_handoff',
)['target_surface'] == 'upload_complete'
assert action_presentation(
'mark_manual_uploaded', gate_code='manual_upload_handoff',
)['target_surface'] == 'upload_complete'
def test_manual_upload_handoff_authorizes_excel_regeneration_at_artifact_anchor():
"""已到人工上传交接时,Excel 重生仍须由当前 Gate 合法授权并回到产物位置。"""
from app.services.shipping_notice.recovery_plan_contract import recovery_plan_for_action
assert action_belongs_to_gate(
gate_code='manual_upload_handoff',
action_code='regenerate_excel_artifact',
) is True
plan = recovery_plan_for_action(
current_gate='manual_upload_handoff',
action_code='regenerate_excel_artifact',
)
assert plan['ui_placement'] == {
'target_surface': 'fulfillment_prep',
'target_anchor': 'excel_artifact',
}
def test_gate_action_presentation_declares_ui_dispatch_without_frontend_action_code_inference():
"""非 mutation 动作必须由合同明确其页面宿主能力。"""
assert action_presentation('mark_manual_uploaded') == {
'code': 'mark_manual_uploaded',
'label_key': 'workspace.shippingNotice.processGate.actionCodes.mark_manual_uploaded',
'kind': 'current_gate',
'dispatch': 'dialog',
'ui_handler': 'manual_upload_evidence',
}
assert action_presentation('confirm_customer') == {
'code': 'confirm_customer',
'label_key': 'workspace.shippingNotice.processGate.actionCodes.confirm_customer',
'kind': 'current_gate',
'dispatch': 'navigation',
'ui_handler': 'customer_resolution',
}
def test_every_gate_declares_a_surface_and_anchor_for_its_actions():
"""所有 Gate 的动作位置必须在 Gate 定义处声明,避免前端或动作码映射猜测。"""
for gate in PROCESS_GATE_DEFINITIONS:
placement = gate['ui_placement']
for action in (gate.get('default_next_actions') or {}).values():
if action:
presentation = action_presentation(action, gate_code=gate['gate_code'])
assert presentation is not None
assert presentation['target_surface'] == placement['target_surface']
assert presentation['target_anchor'] == placement['target_anchor']
def test_process_gate_reason_ownership_is_unique():
"""
每个阻断原因码恰好映射一个 owning_gate,覆盖率 100%。
@@ -240,6 +327,63 @@ def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch
]
def test_inventory_shortage_with_active_snapshot_projects_rematch_and_rpa_refresh(app, tmp_path):
"""库存不足时,已确认的活动 Excel 必须可重匹配;重新获取库存才是第二入口。"""
from app import db
from app.models import (
ShippingInventoryFile,
ShippingNotice,
ShippingProcessExecution,
ShippingProcessGate,
ShippingTaskInventoryLink,
)
from app.services.shipping_notice.process_gate_projection import project_user_gate_summary
inventory_path = tmp_path / 'active-inventory.xlsx'
inventory_path.write_bytes(b'confirmed inventory')
task = ShippingNotice(
task_no='SN-SUFFICIENCY-ACTIVE-SNAPSHOT',
inventory_lines_json=[{'part_number': 'P-1', 'available_qty': 2}],
)
inventory_file = ShippingInventoryFile(
inventory_file_no='SIF-SUFFICIENCY-ACTIVE-SNAPSHOT',
storage_path=str(inventory_path),
snapshot_status='ready',
mapping_confirmed=True,
inventory_lines_json=[{'part_number': 'P-1', 'available_qty': 2}],
line_count=1,
)
db.session.add_all([task, inventory_file])
db.session.flush()
db.session.add(ShippingTaskInventoryLink(
task_id=int(task.id), inventory_file_id=int(inventory_file.id), is_active=True,
))
execution = ShippingProcessExecution(
execution_no='EXE-SUFFICIENCY-ACTIVE-SNAPSHOT', task_id=int(task.id), status='blocked',
current_gate_code='inventory_sufficiency', lock_version=1,
)
db.session.add(execution)
db.session.flush()
db.session.add(ShippingProcessGate(
execution_id=int(execution.id), gate_code='inventory_sufficiency', sequence_no=16,
status='blocked_manual', evaluation_version=1,
blocking_reason_code='inventory_insufficient', next_action_code='open_shortage_review',
))
db.session.flush()
summary = project_user_gate_summary(execution)
# 有效 Excel 是匹配的输入事实;缺口只阻断履约决定,不能迫使用户再次抓取文件。
assert summary['next_action_code'] == 'retry_inventory_matching'
assert summary['allowed_actions'] == [
'retry_inventory_matching',
'retry_inventory_preparation',
]
assert [item['action_code'] for item in summary['recovery_targets']] == [
'retry_inventory_preparation',
]
def test_user_gate_summary_exposes_sanitized_failure_detail_for_any_gate(app, monkeypatch):
"""所有 Gate 均应把当前 Attempt 的脱敏失败详情投影给用户,而非只显示泛化原因。"""
from types import SimpleNamespace
@@ -310,15 +454,15 @@ def test_user_gate_summary_repairs_stale_rpa_action_for_gate19(app, monkeypatch)
assert summary['owner_type'] == 'human'
def test_inventory_preparation_keeps_controlled_upload_as_a_secondary_gate_action(app, monkeypatch):
"""库存准备以重试为主动作,受控上传仅保留给 Gate 工作台。"""
def test_inventory_preparation_exposes_only_rpa_retry(app, monkeypatch):
"""库存准备不再提供库存文件上传旁路,仅允许重试 RPA。"""
from types import SimpleNamespace
from app.services.shipping_notice import process_gate_projection as projection
execution = SimpleNamespace(
id=1, execution_no='EXE-INVENTORY-1', status='blocked',
current_gate_code='inventory_preparation',
primary_next_action_code='upload_inventory_file',
primary_next_action_code='retry_inventory_preparation',
responsible_party='worker', lock_version=1, review_case_id=None, task_id=99,
)
monkeypatch.setattr(
@@ -326,13 +470,13 @@ def test_inventory_preparation_keeps_controlled_upload_as_a_secondary_gate_actio
'serialize_process_execution',
lambda _execution, include_diagnostics=False: {
'execution_no': 'EXE-INVENTORY-1', 'status': 'blocked',
'primary_next_action_code': 'upload_inventory_file',
'primary_next_action_code': 'retry_inventory_preparation',
'responsible_party': 'worker', 'recovery_targets': [],
'active_recovery_plans': [], 'gates': [],
'current_gate': {
'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
'blocking_reason_code': 'inventory_file_empty',
'next_action_code': 'upload_inventory_file', 'evaluation_version': 3,
'next_action_code': 'retry_inventory_preparation', 'evaluation_version': 3,
},
},
)
@@ -341,14 +485,11 @@ def test_inventory_preparation_keeps_controlled_upload_as_a_secondary_gate_actio
assert summary['next_action_code'] == 'retry_inventory_preparation'
assert summary['primary_action']['code'] == 'retry_inventory_preparation'
assert summary['allowed_actions'] == [
'retry_inventory_preparation',
'upload_inventory_file',
]
assert summary['allowed_actions'] == ['retry_inventory_preparation']
def test_user_gate_summary_exposes_manual_gate_evidence_confirmation(app, monkeypatch):
"""Gate 20 只下发受控凭据登记,不把 RPA 重试伪装为人工上传确认。"""
def test_user_gate_summary_exposes_manual_gate_evidence_and_rpa_retry(app, monkeypatch):
"""Gate 20 保持凭据登记主动作,并显式下发可选 RPA 重试。"""
from types import SimpleNamespace
from app.services.shipping_notice import process_gate_projection as projection
@@ -376,7 +517,10 @@ def test_user_gate_summary_exposes_manual_gate_evidence_confirmation(app, monkey
summary = projection.project_user_gate_summary(execution)
assert summary['next_action_code'] == 'mark_manual_uploaded'
assert summary['allowed_actions'] == ['mark_manual_uploaded']
assert summary['allowed_actions'] == [
'mark_manual_uploaded',
'retry_freight_upload_rpa',
]
assert summary['owner_type'] == 'human'
@@ -410,38 +554,81 @@ def test_manual_upload_handoff_projects_evidence_confirmation_as_primary_action(
summary = projection.project_user_gate_summary(execution)
assert summary['next_action_code'] == 'mark_manual_uploaded'
assert summary['allowed_actions'] == ['mark_manual_uploaded']
assert summary['allowed_actions'] == [
'mark_manual_uploaded',
'retry_freight_upload_rpa',
]
assert summary['primary_action']['target_surface'] == 'upload_complete'
assert summary['primary_action']['target_anchor'] == 'manual_upload'
def test_inventory_source_gate_summary_does_not_expose_line_decision_side_actions(app, monkeypatch):
"""规则建议和保留人工决定只属于订单复核明细行,不能泄漏到 Gate 卡。"""
def test_manual_upload_handoff_projects_excel_recovery_at_artifact_anchor(app, monkeypatch):
"""跨 Gate Excel 恢复必须采用 RecoveryPlan 的位置,不能继承 Gate 20 的上传位置。"""
from types import SimpleNamespace
from app.services.shipping_notice import process_gate_projection as projection
execution = SimpleNamespace(
id=1, execution_no='EXE-ROUTING', status='blocked',
current_gate_code='inventory_source_routing', primary_next_action_code='open_inventory_source_review',
id=1, execution_no='EXE-MANUAL-EXCEL', status='blocked',
current_gate_code='manual_upload_handoff',
primary_next_action_code='regenerate_manual_upload_todo',
responsible_party='owner', lock_version=1, review_case_id=None, task_id=99,
)
monkeypatch.setattr(
projection,
'serialize_process_execution',
lambda _execution, include_diagnostics=False: {
'execution_no': 'EXE-MANUAL-EXCEL', 'status': 'blocked',
'primary_next_action_code': 'regenerate_manual_upload_todo',
'responsible_party': 'owner', 'active_recovery_plans': [], 'gates': [],
'recovery_targets': [{'action_code': 'regenerate_excel_artifact'}],
'current_gate': {
'gate_code': 'manual_upload_handoff', 'status': 'blocked_manual',
'blocking_reason_code': 'manual_upload_pending',
'next_action_code': 'regenerate_manual_upload_todo', 'evaluation_version': 3,
},
},
)
monkeypatch.setattr(projection, '_excel_regeneration_allowed', lambda **_: True)
summary = projection.project_user_gate_summary(execution)
regeneration = next(
item for item in summary['action_presentation']
if item['code'] == 'regenerate_excel_artifact'
)
assert regeneration['target_surface'] == 'fulfillment_prep'
assert regeneration['target_anchor'] == 'excel_artifact'
def test_inventory_source_gate_summary_exposes_no_manual_selection_action(app, monkeypatch):
"""库存源路由只允许自动重算,Gate 卡不得暴露人工选源或确认。"""
from types import SimpleNamespace
from app.services.shipping_notice import process_gate_projection as projection
execution = SimpleNamespace(
id=1, execution_no='EXE-ROUTING', status='blocked',
current_gate_code='inventory_source_routing', primary_next_action_code='retry_with_latest_rules',
responsible_party='system', lock_version=1, review_case_id=None, task_id=99,
)
monkeypatch.setattr(
projection,
'serialize_process_execution',
lambda _execution, include_diagnostics=False: {
'execution_no': 'EXE-ROUTING', 'status': 'blocked',
'primary_next_action_code': 'open_inventory_source_review',
'responsible_party': 'owner', 'recovery_targets': [],
'primary_next_action_code': 'retry_with_latest_rules',
'responsible_party': 'system', 'recovery_targets': [],
'active_recovery_plans': [], 'gates': [],
'current_gate': {
'gate_code': 'inventory_source_routing', 'status': 'blocked_manual',
'blocking_reason_code': 'no_inventory_source_candidates',
'next_action_code': 'open_inventory_source_review', 'evaluation_version': 3,
'next_action_code': 'retry_with_latest_rules', 'evaluation_version': 3,
},
},
)
summary = projection.project_user_gate_summary(execution)
assert summary['allowed_actions'] == ['open_inventory_source_review']
assert summary['allowed_actions'] == []
def test_process_gate_dependency_integrity_and_excel_only_scope():