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

+11 -21
View File
@@ -304,7 +304,6 @@ def test_confirm_inventory_source_route_returns_json(app, client):
task = ShippingNotice(
task_no="SN-HTTP-CONFIRM-SRC",
source_type="manual",
process_status="pending_review",
pending_human_reason="inventory_source_unresolved",
ship_to="Dublin",
lines_json=[{"part_number": "A001", "qty": 1, "reservation_id": "R1"}],
@@ -339,7 +338,7 @@ def test_legacy_inventory_mapping_decisions_are_rejected(app, client, decision):
"""已启用库存站点不得通过任务决策重开旧列映射路径。"""
headers = _tool_headers(app)
with app.app_context():
task = ShippingNotice(task_no=f"SN-LEGACY-MAP-{decision}", source_type="manual", process_status="waiting_inventory")
task = ShippingNotice(task_no=f"SN-LEGACY-MAP-{decision}", source_type="manual")
db.session.add(task)
db.session.commit()
@@ -363,7 +362,6 @@ def test_reparse_inventory_clears_derived_state_and_deactivates_current_link(app
task = ShippingNotice(
task_no="SN-REUPLOAD-INVENTORY",
source_type="manual",
process_status="matched",
inventory_lines_json=[{"part_number": "A001", "available_qty": 10}],
match_status="fulfillable",
line_results_json=[{"part_number": "A001"}],
@@ -403,7 +401,7 @@ def test_reparse_inventory_clears_derived_state_and_deactivates_current_link(app
task = ShippingNotice.query.filter_by(task_no="SN-REUPLOAD-INVENTORY").one()
link = ShippingTaskInventoryLink.query.filter_by(task_id=task.id).one()
assert link.is_active is False
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == "inv_unavail"
assert task.pending_human_reason == "inv_unavail"
assert task.inventory_lines_json is None
assert task.match_status is None
@@ -519,7 +517,6 @@ def test_retry_rpa_force_refresh_clears_derived_inventory_state(app, client, tmp
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "inventory_ready"
task.review_status = None
task.pending_human_reason = "inv_unavail"
task.inventory_lines_json = [{"part_number": "OLD", "reservation_id": "12345", "available_qty": 3}]
@@ -542,7 +539,6 @@ def test_retry_rpa_force_refresh_clears_derived_inventory_state(app, client, tmp
}
}
seed_task_inventory_source(task, source_code="DSV360_AWSDU")
task.process_status = "parsed"
db.session.commit()
from app.services.shipping_notice import decision_workflow
@@ -555,7 +551,7 @@ def test_retry_rpa_force_refresh_clears_derived_inventory_state(app, client, tmp
with app.app_context():
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == "rpa_pending"
assert task.pending_human_reason == "rpa_pending"
assert task.review_status is None
assert task.inventory_lines_json is None
@@ -601,7 +597,6 @@ def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "waiting_inventory"
task.pending_human_reason = PH_RPA_PENDING
task.step_payload_json = {
"rpa_inventory_source": {
@@ -628,7 +623,7 @@ def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert result["status"] == "needs_human"
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == PH_RPA_EXHAUSTED
assert task.pending_human_reason == PH_RPA_EXHAUSTED
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_failed").count() == 1
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_triggered").count() == 1
@@ -665,7 +660,6 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "waiting_inventory"
task.pending_human_reason = PH_RPA_EXHAUSTED
task.step_payload_json = {
"rpa_inventory_source": {
@@ -677,7 +671,6 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
}
}
seed_task_inventory_source(task, source_code="DSV360_AWSDU")
task.process_status = "parsed"
base_time = datetime.utcnow() - timedelta(minutes=5)
for idx in range(3):
db.session.add(
@@ -700,7 +693,7 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
with app.app_context():
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == "rpa_pending"
assert task.pending_human_reason == "rpa_pending"
assert task.error_message is None
progress = (task.step_payload_json or {}).get("current_step_progress") or {}
@@ -749,7 +742,6 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
task = ShippingNotice.query.filter_by(task_no=task_id).first()
assert task is not None
_attach_dynamic_order(task, part_number='A001', reservation_id='12345', quantity=1)
task.process_status = "waiting_inventory"
task.pending_human_reason = PH_RPA_PENDING
task.step_payload_json = {
"rpa_inventory_source": {
@@ -777,7 +769,7 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
assert task is not None
assert result["started"] == 1
assert result["skipped"] == 0
assert task.process_status == "waiting_inventory"
assert task.pending_human_reason == PH_RPA_EXHAUSTED
assert task.pending_human_reason == PH_RPA_EXHAUSTED
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_failed").count() == 1
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_triggered").count() == 1
@@ -791,7 +783,6 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
first = ShippingNotice(
task_no="SN-MULTI-CONV-001",
conversation_id="conv-test-multi",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -800,7 +791,6 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
second = ShippingNotice(
task_no="SN-MULTI-CONV-002",
conversation_id="conv-test-multi",
process_status="pending_review",
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
@@ -835,8 +825,8 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
.order_by(ShippingNotice.task_no)
.all()
}
assert rows["SN-MULTI-CONV-001"].process_status == "pending_review"
assert rows["SN-MULTI-CONV-002"].process_status == "pending_review"
assert rows["SN-MULTI-CONV-001"].review_status == "parse_review"
assert rows["SN-MULTI-CONV-002"].review_status == "parse_review"
def test_submit_decision_retry_rpa_routes_to_formal_gate_action(app, client, monkeypatch):
@@ -892,10 +882,10 @@ def test_chat_actions_empty_when_task_rejected(app):
task = ShippingNotice(
task_no="SN-20260101-TEST0001",
source_type="manual",
process_status="rejected",
review_status="rejected",
)
assert human_options_for_task(task) == []
ui_state = build_task_ui_state(task)
assert ui_state["checkpoint"] == "rejected"
assert ui_state["action_buttons"] == []
assert ui_state["checkpoint"]["code"] == "rejected"
assert ui_state["actions"] == {"primary": None, "secondary": []}
assert "action_buttons" not in ui_state