feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ffc0d4a430
commit
39fe3c05f2
453 files changed
+17945
-8646
No files matched your search
@@ -55,18 +55,18 @@ def test_inventory_source_routing_primary_retry_action():
|
||||
核心逻辑:primary_next_action_for_gate 禁止前端本地推导。
|
||||
"""
|
||||
action = primary_next_action_for_gate(
|
||||
gate_code='inventory_source_routing',
|
||||
gate_code='onhand_source_routing',
|
||||
status='blocked_retryable',
|
||||
)
|
||||
assert action == 'retry_with_latest_rules'
|
||||
assert primary_next_action_for_gate(
|
||||
gate_code='inventory_source_routing', status='blocked_manual',
|
||||
gate_code='onhand_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',
|
||||
gate_code='onhand_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',
|
||||
gate_code='onhand_field_mapping', action_code='confirm_inventory_field_mapping',
|
||||
) is False
|
||||
|
||||
|
||||
@@ -83,16 +83,16 @@ def test_gate_action_contract_rejects_inventory_reroute_for_excel_gate():
|
||||
|
||||
|
||||
def test_inventory_preparation_timeout_prefers_merged_rematch_without_standalone_reload():
|
||||
"""RPA 超时后主恢复已合并为 retry_inventory_matching(复用快照重匹配,无则 RPA);
|
||||
reload_inventory_result 不再作为独立主动作。retry_inventory_matching 现属库存准备/匹配/充足性 Gate。"""
|
||||
"""RPA 超时后主恢复已合并为 retry_onhand_matching(复用快照重匹配,无则 RPA);
|
||||
reload_onhand_result 不再作为独立主动作。retry_onhand_matching 现属库存准备/匹配/充足性 Gate。"""
|
||||
assert action_belongs_to_gate(
|
||||
gate_code='inventory_preparation', action_code='retry_inventory_matching',
|
||||
gate_code='onhand_preparation', action_code='retry_onhand_matching',
|
||||
) is True
|
||||
assert action_belongs_to_gate(
|
||||
gate_code='inventory_matching', action_code='retry_inventory_matching',
|
||||
gate_code='onhand_matching', action_code='retry_onhand_matching',
|
||||
) is True
|
||||
assert action_belongs_to_gate(
|
||||
gate_code='inventory_sufficiency', action_code='retry_inventory_matching',
|
||||
gate_code='onhand_sufficiency', action_code='retry_onhand_matching',
|
||||
) is True
|
||||
|
||||
|
||||
@@ -105,9 +105,9 @@ def test_inventory_sufficiency_actions_keep_business_specific_labels():
|
||||
'dispatch': 'navigation',
|
||||
'ui_handler': 'shortage_review',
|
||||
}
|
||||
assert action_presentation('retry_inventory_from_matching') == {
|
||||
'code': 'retry_inventory_from_matching',
|
||||
'label_key': 'workspace.shippingNotice.processGate.actionCodes.retry_inventory_from_matching',
|
||||
assert action_presentation('retry_onhand_from_matching') == {
|
||||
'code': 'retry_onhand_from_matching',
|
||||
'label_key': 'workspace.shippingNotice.processGate.actionCodes.retry_onhand_from_matching',
|
||||
'kind': 'recovery',
|
||||
'dispatch': 'mutation',
|
||||
}
|
||||
@@ -208,7 +208,7 @@ def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technica
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-INV-1', status='blocked',
|
||||
current_gate_code='inventory_matching', primary_next_action_code='retry_inventory_matching',
|
||||
current_gate_code='onhand_matching', primary_next_action_code='retry_onhand_matching',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -216,16 +216,16 @@ def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technica
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-INV-1', 'status': 'blocked',
|
||||
'primary_next_action_code': 'retry_inventory_matching',
|
||||
'primary_next_action_code': 'retry_onhand_matching',
|
||||
'responsible_party': 'worker',
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_matching',
|
||||
'gate_code': 'onhand_matching',
|
||||
'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_incomplete',
|
||||
'next_action_code': 'retry_inventory_matching',
|
||||
'next_action_code': 'retry_onhand_matching',
|
||||
},
|
||||
'recovery_targets': [
|
||||
{'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'},
|
||||
{'action_code': 'retry_onhand_from_preparation', 'target_gate': 'onhand_preparation'},
|
||||
],
|
||||
'gates': [], 'active_recovery_plans': [],
|
||||
},
|
||||
@@ -233,15 +233,15 @@ def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technica
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['current_blocking_gate']['gate_code'] == 'inventory_matching'
|
||||
assert summary['next_action_code'] == 'open_inventory_match_review'
|
||||
assert summary['current_blocking_gate']['gate_code'] == 'onhand_matching'
|
||||
assert summary['next_action_code'] == 'open_onhand_match_review'
|
||||
assert summary['owner_type'] == 'human'
|
||||
assert summary['technical_auto_only'] is False
|
||||
# 侧路动作(override_line_inventory_source,方案 3·放开)先于 RecoveryPlan 复核入口。
|
||||
assert summary['allowed_actions'] == [
|
||||
'open_inventory_match_review',
|
||||
'override_line_inventory_source',
|
||||
'retry_inventory_from_preparation',
|
||||
'open_onhand_match_review',
|
||||
'override_line_onhand_source',
|
||||
'retry_onhand_from_preparation',
|
||||
]
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch
|
||||
|
||||
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',
|
||||
current_gate_code='onhand_matching', primary_next_action_code='open_onhand_match_review',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=99,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -260,17 +260,17 @@ def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-INV-OT-1', 'status': 'blocked',
|
||||
'primary_next_action_code': 'open_inventory_match_review',
|
||||
'primary_next_action_code': 'open_onhand_match_review',
|
||||
'responsible_party': 'worker',
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_matching',
|
||||
'gate_code': 'onhand_matching',
|
||||
'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_incomplete',
|
||||
'next_action_code': 'open_inventory_match_review',
|
||||
'next_action_code': 'open_onhand_match_review',
|
||||
},
|
||||
'recovery_targets': [
|
||||
{'action_code': 'open_inventory_match_review', 'target_gate': 'inventory_matching'},
|
||||
{'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'},
|
||||
{'action_code': 'open_onhand_match_review', 'target_gate': 'onhand_matching'},
|
||||
{'action_code': 'retry_onhand_from_preparation', 'target_gate': 'onhand_preparation'},
|
||||
],
|
||||
'gates': [], 'active_recovery_plans': [],
|
||||
},
|
||||
@@ -278,14 +278,14 @@ def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['next_action_code'] == 'retry_inventory_matching'
|
||||
assert summary['next_action_code'] == 'retry_onhand_matching'
|
||||
assert summary['allowed_actions'] == [
|
||||
'retry_inventory_matching',
|
||||
'override_line_inventory_source',
|
||||
'retry_inventory_from_preparation',
|
||||
'retry_onhand_matching',
|
||||
'override_line_onhand_source',
|
||||
'retry_onhand_from_preparation',
|
||||
]
|
||||
assert summary['recovery_targets'] == [
|
||||
{'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'},
|
||||
{'action_code': 'retry_onhand_from_preparation', 'target_gate': 'onhand_preparation'},
|
||||
]
|
||||
|
||||
|
||||
@@ -293,38 +293,38 @@ def test_inventory_shortage_with_active_snapshot_projects_rematch_and_rpa_refres
|
||||
"""库存不足时,已确认的活动 Excel 必须可重匹配;重新获取库存才是第二入口。"""
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingInventoryFile,
|
||||
FreightRpaOnhandReportFile,
|
||||
ShippingOrderTask,
|
||||
ShippingProcessExecution,
|
||||
ShippingProcessGate,
|
||||
ShippingTaskInventoryLink,
|
||||
ShippingTaskOnhandLink,
|
||||
)
|
||||
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 = ShippingOrderTask(task_no='OT-SUFFICIENCY-ACTIVE-SNAPSHOT', user_id=1)
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-SUFFICIENCY-ACTIVE-SNAPSHOT',
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_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}],
|
||||
onhand_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,
|
||||
db.session.add(ShippingTaskOnhandLink(
|
||||
task_id=int(task.id), onhand_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,
|
||||
current_gate_code='onhand_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,
|
||||
execution_id=int(execution.id), gate_code='onhand_sufficiency', sequence_no=16,
|
||||
status='blocked_manual', evaluation_version=1,
|
||||
blocking_reason_code='inventory_insufficient', next_action_code='open_shortage_review',
|
||||
))
|
||||
@@ -333,13 +333,13 @@ def test_inventory_shortage_with_active_snapshot_projects_rematch_and_rpa_refres
|
||||
summary = project_user_gate_summary(execution)
|
||||
|
||||
# 有效 Excel 是匹配的输入事实;缺口只阻断履约决定,不能迫使用户再次抓取文件。
|
||||
assert summary['next_action_code'] == 'retry_inventory_matching'
|
||||
assert summary['next_action_code'] == 'retry_onhand_matching'
|
||||
assert summary['allowed_actions'] == [
|
||||
'retry_inventory_matching',
|
||||
'retry_inventory_preparation',
|
||||
'retry_onhand_matching',
|
||||
'retry_onhand_preparation',
|
||||
]
|
||||
assert [item['action_code'] for item in summary['recovery_targets']] == [
|
||||
'retry_inventory_preparation',
|
||||
'retry_onhand_preparation',
|
||||
]
|
||||
|
||||
|
||||
@@ -420,8 +420,8 @@ def test_inventory_preparation_exposes_only_rpa_retry(app, monkeypatch):
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-INVENTORY-1', status='blocked',
|
||||
current_gate_code='inventory_preparation',
|
||||
primary_next_action_code='retry_inventory_preparation',
|
||||
current_gate_code='onhand_preparation',
|
||||
primary_next_action_code='retry_onhand_preparation',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=99,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -429,38 +429,38 @@ def test_inventory_preparation_exposes_only_rpa_retry(app, monkeypatch):
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-INVENTORY-1', 'status': 'blocked',
|
||||
'primary_next_action_code': 'retry_inventory_preparation',
|
||||
'primary_next_action_code': 'retry_onhand_preparation',
|
||||
'responsible_party': 'worker', 'recovery_targets': [],
|
||||
'active_recovery_plans': [], 'gates': [],
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'gate_code': 'onhand_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_file_empty',
|
||||
'next_action_code': 'retry_inventory_preparation', 'evaluation_version': 3,
|
||||
'next_action_code': 'retry_onhand_preparation', 'evaluation_version': 3,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['next_action_code'] == 'retry_inventory_preparation'
|
||||
assert summary['primary_action']['code'] == 'retry_inventory_preparation'
|
||||
assert summary['next_action_code'] == 'retry_onhand_preparation'
|
||||
assert summary['primary_action']['code'] == 'retry_onhand_preparation'
|
||||
# 库存准备不再提供库存文件上传旁路;主线仅重试 RPA,并保留行级库存源人工覆写(方案 3·放开)。
|
||||
assert summary['allowed_actions'] == [
|
||||
'retry_inventory_preparation',
|
||||
'override_line_inventory_source',
|
||||
'retry_onhand_preparation',
|
||||
'override_line_onhand_source',
|
||||
]
|
||||
|
||||
|
||||
def test_inventory_rpa_timeout_prefers_merged_rematch(app, monkeypatch):
|
||||
"""RPA 超时主恢复已合并为 retry_inventory_matching(复用快照重匹配,无则 RPA),
|
||||
不再直接指向孤立的 reload_inventory_result 或新 RPA 请求。"""
|
||||
"""RPA 超时主恢复已合并为 retry_onhand_matching(复用快照重匹配,无则 RPA),
|
||||
不再直接指向孤立的 reload_onhand_result 或新 RPA 请求。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-INVENTORY-TIMEOUT', status='blocked',
|
||||
current_gate_code='inventory_preparation',
|
||||
primary_next_action_code='retry_inventory_preparation',
|
||||
current_gate_code='onhand_preparation',
|
||||
primary_next_action_code='retry_onhand_preparation',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=99,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -468,27 +468,27 @@ def test_inventory_rpa_timeout_prefers_merged_rematch(app, monkeypatch):
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-INVENTORY-TIMEOUT', 'status': 'blocked',
|
||||
'primary_next_action_code': 'retry_inventory_preparation',
|
||||
'primary_next_action_code': 'retry_onhand_preparation',
|
||||
'responsible_party': 'worker', 'recovery_targets': [],
|
||||
'active_recovery_plans': [], 'gates': [],
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_preparation', 'status': 'blocked_retryable',
|
||||
'blocking_reason_code': 'inventory_rpa_timeout',
|
||||
'next_action_code': 'retry_inventory_preparation', 'evaluation_version': 3,
|
||||
'gate_code': 'onhand_preparation', 'status': 'blocked_retryable',
|
||||
'blocking_reason_code': 'onhand_rpa_timeout',
|
||||
'next_action_code': 'retry_onhand_preparation', 'evaluation_version': 3,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['next_action_code'] == 'retry_inventory_matching'
|
||||
assert summary['primary_action']['code'] == 'retry_inventory_matching'
|
||||
assert summary['next_action_code'] == 'retry_onhand_matching'
|
||||
assert summary['primary_action']['code'] == 'retry_onhand_matching'
|
||||
# 主动作=复用快照重匹配(无则 RPA);侧路保留 retry_inventory_preparation(显式 RPA 重试)与
|
||||
# override_line_inventory_source(行级库存源人工覆写,方案 3·放开)。
|
||||
assert summary['allowed_actions'] == [
|
||||
'retry_inventory_matching',
|
||||
'retry_inventory_preparation',
|
||||
'override_line_inventory_source',
|
||||
'retry_onhand_matching',
|
||||
'retry_onhand_preparation',
|
||||
'override_line_onhand_source',
|
||||
]
|
||||
|
||||
|
||||
@@ -605,7 +605,7 @@ def test_inventory_source_gate_summary_exposes_no_manual_selection_action(app, m
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-ROUTING', status='blocked',
|
||||
current_gate_code='inventory_source_routing', primary_next_action_code='retry_with_latest_rules',
|
||||
current_gate_code='onhand_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(
|
||||
@@ -617,7 +617,7 @@ def test_inventory_source_gate_summary_exposes_no_manual_selection_action(app, m
|
||||
'responsible_party': 'system', 'recovery_targets': [],
|
||||
'active_recovery_plans': [], 'gates': [],
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_source_routing', 'status': 'blocked_manual',
|
||||
'gate_code': 'onhand_source_routing', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'no_inventory_source_candidates',
|
||||
'next_action_code': 'retry_with_latest_rules', 'evaluation_version': 3,
|
||||
},
|
||||
@@ -626,21 +626,21 @@ def test_inventory_source_gate_summary_exposes_no_manual_selection_action(app, m
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['allowed_actions'] == ['override_line_inventory_source']
|
||||
assert summary['allowed_actions'] == ['override_line_onhand_source']
|
||||
|
||||
|
||||
def test_process_gate_dependency_integrity_and_excel_only_scope():
|
||||
"""
|
||||
校验依赖图完整性,并锁定「仅重生 Excel」不得失效库存匹配。
|
||||
|
||||
核心逻辑:依赖自检 + excel_regeneration_only 显式排除 inventory_matching。
|
||||
核心逻辑:依赖自检 + excel_regeneration_only 显式排除 onhand_matching。
|
||||
"""
|
||||
# [STEP 1] 前置依赖与失效规则仅引用已知门禁
|
||||
assert_process_gate_dependency_integrity()
|
||||
|
||||
# [STEP 2] 仅重生 Excel:失效 artifact + 人工上传,不碰库存匹配
|
||||
excel_only = compute_invalidated_gates('excel_regeneration_only')
|
||||
assert 'inventory_matching' not in excel_only
|
||||
assert 'onhand_matching' not in excel_only
|
||||
assert 'artifact_generation' in excel_only
|
||||
assert 'freight_upload_rpa' in excel_only
|
||||
assert 'manual_upload_handoff' in excel_only
|
||||
|
||||
Reference in new issue
Block a user