refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段
统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成 设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程 删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本 替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段 更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
1 parent
6684e7181a
commit
5ef8329bd8
178 files changed
+5091
-1734
No files matched your search
@@ -14,6 +14,7 @@ from app.services.shipping_notice.constants import (
|
||||
RS_PARSE_REVIEW,
|
||||
)
|
||||
from app.services.shipping_notice.ui_state import build_task_ui_state
|
||||
from app.services.shipping_notice.ui_state import _unified_actions
|
||||
|
||||
|
||||
_REQUIRED_SUMMARY_KEYS = {
|
||||
@@ -31,29 +32,95 @@ _REQUIRED_SUMMARY_KEYS = {
|
||||
}
|
||||
|
||||
|
||||
def test_unified_actions_deduplicates_gate_primary_action():
|
||||
"""Gate 主动作同时出现在展示列表时,只能渲染一次。"""
|
||||
state = _unified_actions(
|
||||
process_gate={
|
||||
"primary_action": {"code": "open_order_review", "label": "进入订单复核"},
|
||||
"action_presentation": [
|
||||
{"code": "open_order_review", "label": "进入订单复核"},
|
||||
{"code": "view_audit", "label": "查看审计", "kind": "view"},
|
||||
],
|
||||
},
|
||||
action_buttons=[],
|
||||
)
|
||||
|
||||
assert state["primary"]["code"] == "open_order_review"
|
||||
assert [item["code"] for item in state["secondary"]] == ["view_audit"]
|
||||
|
||||
|
||||
def test_unified_action_shape_contains_gate_version_fields():
|
||||
"""统一动作 DTO 必须包含前端提交所需的版本与禁用字段。"""
|
||||
state = _unified_actions(
|
||||
process_gate={
|
||||
"lock_version": 7,
|
||||
"current_gate": {"evaluation_version": 3},
|
||||
"primary_action": {"code": "retry_inventory_matching", "label": "重新匹配"},
|
||||
"action_presentation": [],
|
||||
},
|
||||
action_buttons=[],
|
||||
)
|
||||
assert state["primary"]["expected_gate_version"] == 3
|
||||
assert "disabled_reason" in state["primary"]
|
||||
|
||||
|
||||
def test_build_task_ui_state_summary_has_required_keys(app) -> None:
|
||||
"""summary 必须包含 STP 可解释字段全集。"""
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-SUMMARY",
|
||||
process_status="pending_review",
|
||||
review_status=RS_PARSE_REVIEW,
|
||||
pending_human_reason=PH_LOW_CONF,
|
||||
source_type="manual",
|
||||
)
|
||||
state = build_task_ui_state(task)
|
||||
assert set(_REQUIRED_SUMMARY_KEYS).issubset(state["summary"].keys())
|
||||
assert state["checkpoint"] == CP_PARSE_REVIEW
|
||||
assert state["checkpoint"]["code"] == CP_PARSE_REVIEW
|
||||
assert state["checkpoint_kind"] == "must_human"
|
||||
assert "stp_facts" not in state["summary"]
|
||||
|
||||
|
||||
def test_build_task_ui_state_exposes_four_business_stages_and_unified_actions(app) -> None:
|
||||
"""业务 UI 只消费四阶段与后端统一 actions,不再要求前端解释旧七步。"""
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-STAGE-ACTIONS",
|
||||
review_status=RS_PARSE_REVIEW,
|
||||
pending_human_reason=PH_LOW_CONF,
|
||||
source_type="manual",
|
||||
)
|
||||
state = build_task_ui_state(task)
|
||||
assert state["stage"]["code"] == "order_review"
|
||||
assert state["stage"]["index"] == 2
|
||||
assert state["stage"]["total"] == 4
|
||||
assert state["actions"]["primary"] is not None
|
||||
assert state["actions"]["primary"]["code"] == "confirm"
|
||||
assert all("code" in item and "kind" in item for item in state["actions"]["secondary"])
|
||||
|
||||
|
||||
def test_build_task_ui_state_maps_domain_facts_to_fulfillment_and_upload_stages(app) -> None:
|
||||
"""库存匹配/上传结果只映射四个业务阶段。"""
|
||||
with app.app_context():
|
||||
fulfillment = ShippingNotice(
|
||||
task_no="SN-UI-FULFILLMENT",
|
||||
source_type="manual",
|
||||
match_status="partial",
|
||||
inventory_lines_json=[{"part_number": "P-1"}],
|
||||
)
|
||||
upload = ShippingNotice(
|
||||
task_no="SN-UI-UPLOAD",
|
||||
source_type="manual",
|
||||
upload_status="uploaded",
|
||||
)
|
||||
assert build_task_ui_state(fulfillment)["stage"]["code"] == "fulfillment_prep"
|
||||
assert build_task_ui_state(upload)["stage"]["code"] == "upload_complete"
|
||||
|
||||
|
||||
def test_entry_surface_parse_review_is_review_workbench(app) -> None:
|
||||
"""解析复核应进入人工复核工作台。"""
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-REVIEW",
|
||||
process_status="pending_review",
|
||||
review_status=RS_PARSE_REVIEW,
|
||||
pending_human_reason=PH_LOW_CONF,
|
||||
source_type="manual",
|
||||
@@ -67,18 +134,21 @@ def test_entry_surface_export_ready_is_task_workbench(app) -> None:
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-EXPORT",
|
||||
process_status="matched",
|
||||
source_type="manual",
|
||||
export_file_path="/tmp/shipping-export.xlsx",
|
||||
export_file_name="shipping-export.xlsx",
|
||||
)
|
||||
state = build_task_ui_state(task)
|
||||
assert state["checkpoint"] == CP_EXPORT_READY
|
||||
assert state["checkpoint"]["code"] == CP_EXPORT_READY
|
||||
assert state["checkpoint_kind"] == "wait_manual_upload"
|
||||
assert state["summary"]["entry_surface"] == "task_workbench"
|
||||
assert state["summary"].get("pause_reason_code") == "wait_manual_upload"
|
||||
assert "登记凭据" in str(state["summary"].get("pause_reason") or "")
|
||||
button_ids = [b.get("id") for b in (state.get("action_buttons") or [])]
|
||||
button_ids = [
|
||||
item.get("code")
|
||||
for item in [state["actions"].get("primary"), *(state["actions"].get("secondary") or [])]
|
||||
if item
|
||||
]
|
||||
assert "download_excel" in button_ids
|
||||
assert "mark_manual_uploaded" in button_ids
|
||||
|
||||
@@ -88,7 +158,6 @@ def test_stp_facts_candidates_frozen_projected(app) -> None:
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-STP-FROZEN",
|
||||
process_status="waiting_inventory",
|
||||
source_type="manual",
|
||||
inventory_source_status="candidates_frozen",
|
||||
inventory_source_method="stp_build_freeze",
|
||||
@@ -111,7 +180,6 @@ def test_stp_facts_projects_line_resolutions(app) -> None:
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-STP-LINES",
|
||||
process_status="matched",
|
||||
source_type="manual",
|
||||
match_status="fulfillable",
|
||||
inventory_source_status="resolved",
|
||||
@@ -150,7 +218,6 @@ def test_stp_facts_multi_source_excel_block_legacy_payload(app) -> None:
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no="SN-UI-STP-MULTI",
|
||||
process_status="matched",
|
||||
review_status=RS_SHORTAGE_REVIEW,
|
||||
pending_human_reason="shortage",
|
||||
source_type="manual",
|
||||
|
||||
Reference in new issue
Block a user