refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段

统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
hugo committed 2026-08-15 10:19:10 +08:00
1 parent 6684e7181a
commit 5ef8329bd8
178 files changed
+5091 -1734

No files matched your search

@@ -24,12 +24,37 @@ from app.services.shipping_notice.query_service import (
from app.services.shipping_notice.user_facing_status import TOOL_TASK_DATA_OMIT
def test_chat_match_result_payload_uses_unified_actions_only():
"""Chat 匹配结果不得再把旧 action_buttons 作为按钮来源。"""
from app.services.shipping_notice.chat_action_handlers import _match_result_payload
payload = _match_result_payload(
"SN-ACTIONS-ONLY",
{
"data": {
"match_status": "shortage",
"line_results": [],
"shortage": {"lines": []},
},
"action_buttons": [{"id": "legacy_retry"}],
"ui_state": {
"actions": {
"primary": {"code": "open_shortage_review", "enabled": True},
"secondary": [],
},
},
},
)
assert payload["actions"]["primary"]["code"] == "open_shortage_review"
assert "action_buttons" not in payload
def test_get_task_by_ref_supports_task_no_and_numeric_id(app):
"""task_no 与数字主键均应能解析到同一任务。"""
with app.app_context():
task = ShippingNotice(
task_no="SN-TEST-QUERY-001",
process_status="created",
source_type="manual",
)
from app import db
@@ -47,28 +72,28 @@ def test_get_task_by_ref_supports_task_no_and_numeric_id(app):
def test_list_tasks_for_user_filters_shortage_review_by_user_facing_state(app):
"""库存缺口筛选应读取复核状态,而不是要求不存在的 process_status。"""
"""库存缺口筛选应读取领域事实和复核状态。"""
with app.app_context():
from app import db
shortage = ShippingNotice(
task_no="SN-FILTER-SHORTAGE",
process_status="pending_review",
review_status="shortage_review",
pending_human_reason="shortage",
source_type="manual",
user_id=999999,
)
ordinary = ShippingNotice(
task_no="SN-FILTER-PARSE",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
user_id=2,
)
db.session.add_all([shortage, ordinary])
db.session.commit()
rows = list_tasks_for_user(999999, process_status="shortage_review")
rows = list_tasks_for_user(999999)
assert [item["task_no"] for item in rows] == ["SN-FILTER-SHORTAGE"]
@@ -79,7 +104,7 @@ def test_list_tasks_page_for_user_returns_stable_page_and_total(app):
from app import db
db.session.add_all([
ShippingNotice(task_no=f"SN-PAGE-{index:02d}", process_status="created", source_type="manual")
ShippingNotice(task_no=f"SN-PAGE-{index:02d}", source_type="manual")
for index in range(1, 6)
])
db.session.commit()
@@ -105,13 +130,13 @@ def test_list_tasks_page_for_user_applies_status_filter_before_count(app):
from app import db
db.session.add_all([
ShippingNotice(task_no="SN-PAGE-FILTER-1", process_status="created", source_type="manual"),
ShippingNotice(task_no="SN-PAGE-FILTER-2", process_status="created", source_type="manual"),
ShippingNotice(task_no="SN-PAGE-FILTER-3", process_status="uploaded", source_type="manual"),
ShippingNotice(task_no="SN-PAGE-FILTER-1", source_type="manual"),
ShippingNotice(task_no="SN-PAGE-FILTER-2", source_type="manual"),
ShippingNotice(task_no="SN-PAGE-FILTER-3", upload_status="uploaded", source_type="manual"),
])
db.session.commit()
result = list_tasks_page_for_user(999999, process_status="created", page=1, page_size=10)
result = list_tasks_page_for_user(999999, lifecycle_status="active", page=1, page_size=10)
# 关键断言:uploaded 任务既不在 items 中,也不计入总数。
assert result["total"] == 2
@@ -123,12 +148,11 @@ def test_list_tasks_page_for_user_applies_status_filter_before_count(app):
def test_task_export_error_message_distinct_for_missing_path(app):
"""无导出路径与磁盘缺失应返回不同错误文案。"""
with app.app_context():
empty = ShippingNotice(task_no="SN-NO-EXPORT", process_status="created", source_type="manual")
empty = ShippingNotice(task_no="SN-NO-EXPORT", source_type="manual")
assert task_export_error_message(empty) == "export file not found"
missing = ShippingNotice(
task_no="SN-MISSING-FILE",
process_status="matched",
source_type="manual",
export_file_path="/tmp/not-a-real-shipping-export.xlsx",
)
@@ -140,7 +164,6 @@ def test_task_projection_tool_strips_internal_fields(app):
with app.app_context():
task = ShippingNotice(
task_no="SN-PROJ-TOOL",
process_status="waiting_inventory",
review_status="align_review",
match_status="pending",
pending_human_reason="rpa_pending",
@@ -161,12 +184,11 @@ def test_task_projection_internal_keeps_status_fields(app):
with app.app_context():
task = ShippingNotice(
task_no="SN-PROJ-INT",
process_status="parsed",
review_status="parse_review",
source_type="manual",
)
data = serialize_task(task, TaskProjection.TOOL_INTERNAL)
assert data["process_status"] == "parsed"
assert "review_status" in data
assert data["review_status"] == "parse_review"
@@ -177,7 +199,6 @@ def test_resolve_task_from_payload_by_conversation_id_single_active_task(app):
task = ShippingNotice(
task_no="SN-CONV-1",
conversation_id="conv-abc",
process_status="parsed",
source_type="manual",
)
from app import db
@@ -202,13 +223,11 @@ def test_resolve_task_from_payload_rejects_ambiguous_conversation_id(app):
ShippingNotice(
task_no="SN-CONV-MULTI-1",
conversation_id="conv-multi",
process_status="parsed",
source_type="manual",
),
ShippingNotice(
task_no="SN-CONV-MULTI-2",
conversation_id="conv-multi",
process_status="pending_review",
source_type="manual",
),
]
@@ -232,13 +251,11 @@ def test_task_can_handle_only_creator(app):
owned = ShippingNotice(
task_no="SN-HANDLE-OWN",
process_status="created",
source_type="manual",
user_id=42,
)
orphan = ShippingNotice(
task_no="SN-HANDLE-ORPHAN",
process_status="created",
source_type="manual",
user_id=None,
)
@@ -263,13 +280,11 @@ def test_get_task_for_user_rejects_null_owner(app):
orphan = ShippingNotice(
task_no="SN-NULL-OWNER",
process_status="created",
source_type="manual",
user_id=None,
)
owned = ShippingNotice(
task_no="SN-OWNED",
process_status="created",
source_type="manual",
user_id=7,
)
@@ -291,7 +306,6 @@ def test_serialize_task_summary_enriches_todo_and_can_handle(app):
task = ShippingNotice(
task_no="SN-ENRICH-1",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -306,7 +320,7 @@ def test_serialize_task_summary_enriches_todo_and_can_handle(app):
assert data["todo_category"] == "review"
assert data["created_by"] == 11
assert data["can_handle"] is True
assert data["ui_state"]["checkpoint"] == "parse_review"
assert data["ui_state"]["checkpoint"]["code"] == "parse_review"
assert data["artifact_summary"]["export_file_name"] == "a.xlsx"
no_viewer = serialize_task_summary(task)
@@ -322,7 +336,6 @@ def test_list_my_todos_and_count_buckets(app):
owner = 55
review = ShippingNotice(
task_no="SN-TODO-REVIEW",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -330,7 +343,6 @@ def test_list_my_todos_and_count_buckets(app):
)
upload = ShippingNotice(
task_no="SN-TODO-UPLOAD",
process_status="matched",
source_type="manual",
user_id=owner,
export_file_path="/tmp/u.xlsx",
@@ -338,13 +350,12 @@ def test_list_my_todos_and_count_buckets(app):
)
done = ShippingNotice(
task_no="SN-TODO-DONE",
process_status="uploaded",
source_type="manual",
user_id=owner,
upload_status="uploaded",
)
other = ShippingNotice(
task_no="SN-TODO-OTHER",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -422,7 +433,7 @@ def test_list_my_todos_includes_orphan_parse_failed_intake(app):
"""
未建 OT 且解析失败的 Intake 须进入 pending,并暴露 conversation 深链字段。
断言:item_kind=order_intake;todo_category=intake_parse;count.pending 计入。
断言:item_kind=order_intake;todo_category=intake_parse;count.pending 计入。
"""
with app.app_context():
from app import db
@@ -527,7 +538,6 @@ def test_list_my_todos_total_and_high_page_are_not_capped(app):
tasks = [
ShippingNotice(
task_no=f"SN-TODO-PAGE-{index:04d}",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -578,7 +588,6 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
fixtures = [
ShippingNotice(
task_no="SN-LW-REVIEW",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -586,7 +595,6 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
),
ShippingNotice(
task_no="SN-LW-UPLOAD",
process_status="matched",
source_type="manual",
user_id=owner,
export_file_path="/tmp/lw.xlsx",
@@ -595,7 +603,6 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
ShippingNotice(
task_no="SN-LW-SHORTAGE",
# 不可用 matched:状态机会先落到 ready_export,遮住 shortage 人审分支。
process_status="parsed",
review_status="shortage_review",
pending_human_reason="shortage",
source_type="manual",
@@ -603,13 +610,12 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
),
ShippingNotice(
task_no="SN-LW-DONE",
process_status="uploaded",
upload_status="uploaded",
source_type="manual",
user_id=owner,
),
ShippingNotice(
task_no="SN-LW-PROGRESS",
process_status="parsed",
source_type="manual",
user_id=owner,
),
@@ -620,7 +626,6 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
category_expr = _task_todo_category_sql_expr()
for task in fixtures:
row = SimpleNamespace(
process_status=task.process_status,
review_status=task.review_status,
pending_human_reason=task.pending_human_reason,
shipping_case_id=task.shipping_case_id,
@@ -630,6 +635,7 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
inventory_lines_json=task.inventory_lines_json,
match_status=task.match_status,
export_file_path=task.export_file_path,
upload_status=task.upload_status,
)
expected = task_todo_category(task)
# 轻量路径与 ORM 路径同分类。