feat(shipping-notice): 收敛订单处理状态与履约门禁

This commit is contained in:
hugo committed 2026-09-07 09:42:12 +08:00
1 parent bffcd55b40
commit 70dd0051b8
153 files changed
+10916 -4296

No files matched your search

@@ -340,7 +340,9 @@ def test_serialize_task_summary_enriches_todo_and_can_handle(app):
assert data["todo_category"] == "in_progress"
assert data["created_by"] == 11
assert data["can_handle"] is True
assert data["ui_state"]["checkpoint"]["code"] == "order_freeze"
# 无 Gate 且无 review_status:薄回退不投影 order_freeze
assert data["ui_state"]["position"] is None
assert data["ui_state"]["user_mode"] == "auto_continue"
assert data["artifact_summary"] is None
no_viewer = serialize_task_summary(task)
@@ -575,11 +577,85 @@ def test_freight_notice_groups_upload_mode_reads_attempt_not_stale_column(app):
item = result['items'][0]
assert item['business_no'] == 'WYC26082501'
# 权威事实:人工确认成功 → Attempt.status=succeeded,但 Notice 面必须投影为 uploaded。
assert item['upload_status'] == 'uploaded'
# 权威事实:人工确认成功 → manual;不读陈旧列('rpa')或恒 0/99 的 attempt 计数。
assert item['upload_mode'] == 'manual'
assert item['upload_attempt'] == 1
def test_freight_notice_groups_available_actions_use_order_task_execution(app):
"""货代上传单条菜单必须经 Notice.order_task_id 读 OT Execution,禁止用 Notice.id 查 Gate。
回归点:ShippingProcessExecution.task_id FK 指向 shipping_order_tasks.id;
Artifact.task_id 才是 Notice 主键。若误用 Notice.id,聚合只会留下 download_excel,
行内 RPA/确认上传按钮全部消失。
"""
with app.app_context():
from app import db
from app.models import ShippingProcessExecution, ShippingProcessGate
from app.services.shipping_notice import query_service
# 两张表在空库上都会从 1 起号;只给 OT 表垫一条废数据,强制 Notice.id ≠ OT.id,
# 否则「误用 Notice.id 查 Execution」在单测里会碰巧命中。
db.session.add(ShippingOrderTask(
task_no='OT-GROUP-ACTIONS-PAD', user_id=11, source_type='direct_pdf',
))
db.session.flush()
order_task = ShippingOrderTask(
task_no='OT-GROUP-ACTIONS-1', user_id=11, source_type='direct_pdf',
)
db.session.add(order_task)
db.session.flush()
notice = ShippingNotice(
task_no='SN-GROUP-ACTIONS-1',
business_no='WYC26090601',
source_type='manual',
user_id=11,
order_task_id=order_task.id,
)
db.session.add(notice)
db.session.flush()
# Notice.id 与 OT.id 必须不同,否则会掩盖「误用 Notice.id 查 Execution」的回归。
assert int(notice.id) != int(order_task.id)
execution = ShippingProcessExecution(
execution_no='EXE-GROUP-ACTIONS-1',
task_id=int(order_task.id),
status='blocked',
current_gate_code='manual_upload_handoff',
primary_next_action_code='mark_manual_uploaded',
lock_version=1,
)
db.session.add(execution)
db.session.flush()
db.session.add(ShippingProcessGate(
execution_id=int(execution.id),
gate_code='manual_upload_handoff',
sequence_no=20,
status='blocked_manual',
evaluation_version=1,
blocking_reason_code='manual_upload_pending',
next_action_code='mark_manual_uploaded',
))
order_task.active_process_execution_id = int(execution.id)
db.session.commit()
original_header_reader = query_service.current_header_field_values_or_empty
query_service.current_header_field_values_or_empty = lambda _task: {
'customer_po_number': 'PO-ACTIONS',
}
try:
result = list_freight_notice_groups_for_task(notice, user_id=11)
finally:
query_service.current_header_field_values_or_empty = original_header_reader
actions = set(result['items'][0]['available_actions'] or [])
assert 'mark_manual_uploaded' in actions
assert 'retry_freight_upload_rpa' in actions
def test_list_my_todos_and_count_buckets(app):
"""待办按 OT 复核事实和 Notice 上传事实分类;count 徽标与 pending 一致。"""
with app.app_context():
@@ -1094,8 +1170,10 @@ def test_todo_category_sql_matches_formal_notice_facts(app):
def test_serialize_task_detail_workbench_view_drops_editor_fields(app):
"""工作台 view=workbench 剔除复核编辑器重字段,保留 ui_state/产物/行摘要,全量视图不受影响。"""
"""工作台 view=workbench 跳过 DETAIL 重投影,保留 ui_state/产物/行摘要,全量视图不受影响。"""
with app.app_context():
from unittest.mock import patch
from app import db
from app.services.shipping_notice.query_service import serialize_task_detail
@@ -1106,11 +1184,16 @@ def test_serialize_task_detail_workbench_view_drops_editor_fields(app):
db.session.commit()
full = serialize_task_detail(task, viewer_user_id=11, include_stage_context=True)
wb = serialize_task_detail(
task, viewer_user_id=11, include_stage_context=True, view="workbench",
)
with patch(
'app.services.shipping_notice.query_service.serialize_task',
) as serialize_task_mock:
wb = serialize_task_detail(
task, viewer_user_id=11, include_stage_context=True, view="workbench",
)
# full 保留编辑器重字段;workbench 剔除它们,显著缩小响应体。
# workbench 不得进入 SUMMARY/DETAIL 重投影(算之前就轻)。
serialize_task_mock.assert_not_called()
# full 保留编辑器重字段;workbench 身份壳不含它们。
for key in (
"lines", "order_header", "order_header_fields", "order_line_fields",
):
@@ -1122,3 +1205,5 @@ def test_serialize_task_detail_workbench_view_drops_editor_fields(app):
assert wb["artifact_summary"] is None
assert "notice_line_summary" in wb
assert "export_artifacts" not in wb
assert wb["task_no"] == "OT-WORKBENCH-VIEW"
assert wb["order_task_no"] == "OT-WORKBENCH-VIEW"