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:
hugoandCursor committed 2026-10-19 10:46:06 +08:00
1 parent ffc0d4a430
commit 39fe3c05f2
453 files changed
+17945 -8646

No files matched your search

+29 -29
View File
@@ -37,7 +37,7 @@ def test_user_mode_wait_upload_handoff():
def test_user_mode_must_human():
assert derive_user_mode(
user_status='waiting_human',
gate_code='inventory_matching',
gate_code='onhand_matching',
review_status=None,
lifecycle_stage='fulfillment_prep',
) == 'must_human'
@@ -46,7 +46,7 @@ def test_user_mode_must_human():
def test_user_mode_auto():
assert derive_user_mode(
user_status='running',
gate_code='inventory_preparation',
gate_code='onhand_preparation',
review_status=None,
lifecycle_stage='fulfillment_prep',
) == 'auto_continue'
@@ -59,7 +59,7 @@ def test_position_review_dispositions():
def test_position_fulfillment():
assert derive_position(gate_code='inventory_preparation', review_status=None) == 'inventory_pending'
assert derive_position(gate_code='onhand_preparation', review_status=None) == 'inventory_pending'
assert derive_position(gate_code='artifact_generation', review_status=None) == 'export_ready'
@@ -91,7 +91,7 @@ def test_fetch_gate_positions_batched(app):
user_id=user.id,
conversation_id=session.session_id,
status='waiting_review',
stage='inventory_matching',
stage='onhand_matching',
progress_version=1,
)
ot_b = ShippingOrderTask(
@@ -99,7 +99,7 @@ def test_fetch_gate_positions_batched(app):
user_id=user.id,
conversation_id=session.session_id,
status='processing',
stage='inventory_fetching',
stage='onhand_fetching',
progress_version=1,
)
db.session.add_all([ot_a, ot_b])
@@ -109,21 +109,21 @@ def test_fetch_gate_positions_batched(app):
execution_no='SPE-GATE-POS-A',
task_id=int(ot_a.id),
status='blocked',
current_gate_code='inventory_sufficiency',
current_gate_code='onhand_sufficiency',
),
ShippingProcessExecution(
execution_no='SPE-GATE-POS-B',
task_id=int(ot_b.id),
status='active',
current_gate_code='inventory_preparation',
current_gate_code='onhand_preparation',
),
])
db.session.commit()
result = fetch_gate_positions([int(ot_a.id), int(ot_b.id), 999999])
assert result[int(ot_a.id)]['current_gate_code'] == 'inventory_sufficiency'
assert result[int(ot_a.id)]['current_gate_code'] == 'onhand_sufficiency'
assert result[int(ot_a.id)]['status'] == 'blocked'
assert result[int(ot_b.id)]['current_gate_code'] == 'inventory_preparation'
assert result[int(ot_b.id)]['current_gate_code'] == 'onhand_preparation'
assert 999999 not in result
@@ -140,11 +140,11 @@ def test_early_stop_uses_derive_user_mode(monkeypatch):
'current_gate': {
'status': 'blocked_manual',
'blocking_reason_code': 'inventory_shortage_review_required',
'gate_code': 'inventory_sufficiency',
'gate_code': 'onhand_sufficiency',
},
'responsible_party': 'owner',
'lifecycle_stage': 'fulfillment_prep',
'current_gate_code': 'inventory_sufficiency',
'current_gate_code': 'onhand_sufficiency',
'status': 'blocked',
},
)
@@ -153,9 +153,9 @@ def test_early_stop_uses_derive_user_mode(monkeypatch):
def test_entry_user_mode_inventory_prep_retryable_stays_auto(monkeypatch):
"""
回归:候选已冻结但尚未取库存时,sync 可能把 inventory_preparation 投影为
回归:候选已冻结但尚未取库存时,sync 可能把 onhand_preparation 投影为
blocked_retryable + inventory_file_empty;自动推进入口不得判 must_human 早停,
否则永远进不了 ensure_inventory(复用快照 / 触发 RPA)。
否则永远进不了 ensure_onhand(复用快照 / 触发 RPA)。
"""
from app.services.shipping_notice import progress_workflow as pw
@@ -169,16 +169,16 @@ def test_entry_user_mode_inventory_prep_retryable_stays_auto(monkeypatch):
'current_gate': {
'status': 'blocked_retryable',
'blocking_reason_code': 'inventory_file_empty',
'gate_code': 'inventory_preparation',
'gate_code': 'onhand_preparation',
},
'current_blocking_gate': {
'status': 'blocked_retryable',
'blocking_reason_code': 'inventory_file_empty',
'gate_code': 'inventory_preparation',
'gate_code': 'onhand_preparation',
},
'responsible_party': 'worker',
'lifecycle_stage': 'fulfillment_prep',
'current_gate_code': 'inventory_preparation',
'current_gate_code': 'onhand_preparation',
'status': 'blocked',
'blocking_reason_code': 'inventory_file_empty',
},
@@ -199,20 +199,20 @@ def test_entry_user_mode_inventory_prep_exhausted_still_must_human(monkeypatch):
lambda t: {
'current_blocking_gate': {
'status': 'blocked_retryable',
'blocking_reason_code': 'inventory_rpa_exhausted',
'gate_code': 'inventory_preparation',
'blocking_reason_code': 'onhand_rpa_exhausted',
'gate_code': 'onhand_preparation',
},
'lifecycle_stage': 'fulfillment_prep',
'current_gate_code': 'inventory_preparation',
'current_gate_code': 'onhand_preparation',
'status': 'blocked',
'blocking_reason_code': 'inventory_rpa_exhausted',
'blocking_reason_code': 'onhand_rpa_exhausted',
},
)
assert pw._entry_user_mode(FakeTask()) == 'must_human'
def test_position_inventory_sufficiency():
assert derive_position(gate_code='inventory_sufficiency', review_status=None) == 'shortage_review'
assert derive_position(gate_code='onhand_sufficiency', review_status=None) == 'shortage_review'
def test_todo_category_from_gate_positions():
@@ -227,14 +227,14 @@ def test_todo_category_from_gate_positions():
)
assert (
_todo_category_from_gate(
{'current_gate_code': 'inventory_preparation', 'status': 'active'},
{'current_gate_code': 'onhand_preparation', 'status': 'active'},
None,
)
== 'in_progress'
)
assert (
_todo_category_from_gate(
{'current_gate_code': 'inventory_sufficiency', 'status': 'blocked'},
{'current_gate_code': 'onhand_sufficiency', 'status': 'blocked'},
None,
)
== 'exception'
@@ -257,7 +257,7 @@ def test_user_facing_stage_uses_position(monkeypatch):
)
monkeypatch.setattr(
'app.services.shipping_notice.ui_state._process_gate_user_summary_for_task',
lambda t: {'current_gate_code': 'inventory_preparation'},
lambda t: {'current_gate_code': 'onhand_preparation'},
)
assert ufs.user_facing_task_stage(FakeTask()) == '待上传库存'
@@ -315,7 +315,7 @@ def test_summary_prefers_gate_shortage_over_freeze(monkeypatch):
FakeTask(),
'shortage_review',
user_mode='must_human',
gate_code='inventory_sufficiency',
gate_code='onhand_sufficiency',
)
assert '缺口' in summary['message'] or '库存' in summary['message']
assert summary['user_mode'] == 'must_human'
@@ -332,7 +332,7 @@ def test_notice_text_failure_maps_to_quality_issue():
def test_sql_todo_category_prefers_gate_inventory_sufficiency(app):
"""关键断言:SQL CASE 在 Execution=inventory_sufficiency/blocked 时为 exception。"""
"""关键断言:SQL CASE 在 Execution=onhand_sufficiency/blocked 时为 exception。"""
with app.app_context():
from app import db
from app.models import ShippingOrderTask, ShippingProcessExecution
@@ -345,7 +345,7 @@ def test_sql_todo_category_prefers_gate_inventory_sufficiency(app):
user_id=user.id,
conversation_id=session.session_id,
status='waiting_review',
stage='inventory_matching',
stage='onhand_matching',
progress_version=1,
)
db.session.add(ot)
@@ -355,7 +355,7 @@ def test_sql_todo_category_prefers_gate_inventory_sufficiency(app):
execution_no='SPE-SQL-GATE-SHORT',
task_id=int(ot.id),
status='blocked',
current_gate_code='inventory_sufficiency',
current_gate_code='onhand_sufficiency',
)
)
db.session.commit()
@@ -474,7 +474,7 @@ def test_sql_todo_category_running_inventory_prep_is_in_progress(app):
execution_no='SPE-SQL-RUNNING-PREP',
task_id=int(ot.id),
status='active',
current_gate_code='inventory_preparation',
current_gate_code='onhand_preparation',
)
)
db.session.commit()