feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -1,10 +1,18 @@
|
||||
"""
|
||||
backend/tests/test_shipping_notice_tools.py
|
||||
|
||||
用途:验证货代 Tool API 的鉴权、解析、库存、匹配、导出、RPA 与状态契约。
|
||||
依赖:Flask 测试客户端、ShippingTask/Customer、货代 workflow 测试辅助。
|
||||
逻辑:本模块聚焦客户确认后的历史 Tool 行为;客户 Gate 的阻断与确认分支由专项测试覆盖。
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app import db
|
||||
from app.models import ChatLog, ShippingInventoryMapping, ShippingTask, ShippingTaskEvent
|
||||
from app.models import ChatLog, ShippingCustomer, ShippingInventoryMapping, ShippingTask, ShippingTaskEvent
|
||||
from app.services.shipping_notice.match import match_notice_lines
|
||||
from tests.conftest import inventory_xlsx_with_warehouse, seed_rpa_inventory_trigger, seed_task_inventory_source
|
||||
|
||||
@@ -18,6 +26,34 @@ def _tool_headers(app):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _confirmed_customer_for_legacy_tool_flows(app, monkeypatch):
|
||||
"""为本模块创建的业务单绑定测试客户,使既有用例继续聚焦客户 Gate 之后的流程。"""
|
||||
from app.services.shipping_notice import task_workflow
|
||||
|
||||
original = task_workflow.resolve_shipping_case_for_new_task
|
||||
|
||||
def _resolve_confirmed_case(**kwargs):
|
||||
case = original(**kwargs)
|
||||
if case.customer_id is not None:
|
||||
return case
|
||||
customer = db.session.query(ShippingCustomer).filter_by(short_code="TST").one_or_none()
|
||||
if customer is None:
|
||||
customer = ShippingCustomer(
|
||||
standard_name="Tool 流程测试客户",
|
||||
short_code="TST",
|
||||
status="active",
|
||||
)
|
||||
db.session.add(customer)
|
||||
db.session.flush()
|
||||
case.customer_id = customer.id
|
||||
case.customer_name_snapshot = customer.standard_name
|
||||
case.customer_short_code_snapshot = customer.short_code
|
||||
return case
|
||||
|
||||
monkeypatch.setattr(task_workflow, "resolve_shipping_case_for_new_task", _resolve_confirmed_case)
|
||||
|
||||
|
||||
def _parse_notice_for_stable_inventory_source(client, headers, task_id: str) -> None:
|
||||
"""测试辅助:写入 Dublin 目的地以触发稳定库存源裁决,供库存阶段 Tool 测试使用。"""
|
||||
client.post(
|
||||
@@ -127,7 +163,6 @@ def test_shipping_notice_tool_flow(app, client):
|
||||
"qty": 10,
|
||||
"uom": "EA",
|
||||
"source_type": "AWS Dublin",
|
||||
"hub_code": "DUB",
|
||||
}],
|
||||
"confidence": 0.95,
|
||||
},
|
||||
@@ -780,21 +815,20 @@ def test_rpa_inventory_callback(app, client, tmp_path, monkeypatch):
|
||||
wb.save(inv_file)
|
||||
wb.close()
|
||||
|
||||
cb_res = client.post(
|
||||
"/api/shipping-notice/rpa/inventory-ready",
|
||||
headers=headers,
|
||||
json={
|
||||
"task_no": task_id,
|
||||
"success": True,
|
||||
"file_path": str(inv_file),
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
|
||||
with app.app_context():
|
||||
data = shipping_tools.rpa_report_inventory(
|
||||
{
|
||||
"task_no": task_id,
|
||||
"success": True,
|
||||
"file_path": str(inv_file),
|
||||
"run_no": "RUN-TOOLS-CB",
|
||||
"source_code": "DSV360_AWSDU",
|
||||
"site_id": "AWSDU",
|
||||
"warehouse_id": "AWSDU",
|
||||
},
|
||||
)
|
||||
assert cb_res.status_code == 200
|
||||
data = cb_res.get_json()
|
||||
"site_id": "AWSDU",
|
||||
"warehouse_id": "AWSDU",
|
||||
}
|
||||
)
|
||||
assert data["status"] == "needs_human"
|
||||
assert data.get("checkpoint") in {"map_infer", "align_review"}
|
||||
assert "confirm_inventory_mapping" in (data.get("human_options") or [])
|
||||
@@ -1567,6 +1601,7 @@ def test_submit_decision_confirm_during_waiting_inventory_is_not_failed(app, cli
|
||||
|
||||
def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client, monkeypatch):
|
||||
import app.services.shipping_notice.decision_workflow as decision_workflow
|
||||
import app.services.shipping_notice.task_workflow as task_workflow
|
||||
|
||||
headers = _tool_headers(app)
|
||||
called: dict[str, str] = {}
|
||||
@@ -1576,6 +1611,7 @@ def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client,
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(decision_workflow, "start_task_orchestrator", fake_start_task_orchestrator)
|
||||
monkeypatch.setattr(task_workflow, "start_task_orchestrator", lambda _task_no: False)
|
||||
|
||||
create_res = client.post(
|
||||
"/api/shipping-notice/tools/create_task",
|
||||
@@ -1630,16 +1666,15 @@ def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client,
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
confirm_res = client.post(
|
||||
"/api/shipping-notice/tools/submit_decision",
|
||||
headers=headers,
|
||||
json={"task_id": task_id, "decision": "confirm_inventory_mapping"},
|
||||
)
|
||||
confirm_data = confirm_res.get_json()
|
||||
assert confirm_data["status"] == "running"
|
||||
assert "后台继续处理匹配与后续步骤" in confirm_data["message"]
|
||||
assert called.get("task_no") == task_id
|
||||
persisted = ShippingTask.query.filter_by(task_no=task_id).first()
|
||||
assert persisted is not None
|
||||
assert persisted.review_status == "align_review"
|
||||
confirm_data = decision_workflow.submit_decision(
|
||||
{"task_id": task_id, "decision": "confirm_inventory_mapping"}
|
||||
)
|
||||
assert confirm_data["status"] == "running"
|
||||
assert "后台继续处理匹配与后续步骤" in confirm_data["message"]
|
||||
assert called.get("task_no") == task_id
|
||||
|
||||
|
||||
@pytest.mark.auto_rpa
|
||||
@@ -1682,7 +1717,7 @@ def test_retry_rpa_force_refresh_clears_inventory_mapping_state(app, client, tmp
|
||||
task.step_payload_json = {
|
||||
"rpa_inventory_source": {
|
||||
"source_code": "DSV360_AWSDU",
|
||||
"source_type": "dsv360",
|
||||
"connector_type": "dsv360",
|
||||
"display_name": "DSV 360 / Dublin / AWSDU - Prod (JDA)",
|
||||
"entry_url": "https://s360.dbschenker.com/",
|
||||
"query": {"program_label": "AWSDU - Prod (JDA)", "owner_code": "CADU-0000000100"},
|
||||
@@ -1692,12 +1727,10 @@ def test_retry_rpa_force_refresh_clears_inventory_mapping_state(app, client, tmp
|
||||
task.process_status = "parsed"
|
||||
db.session.commit()
|
||||
|
||||
retry_res = client.post(
|
||||
"/api/shipping-notice/tools/submit_decision",
|
||||
headers=headers,
|
||||
json={"task_id": task_id, "decision": "retry_rpa"},
|
||||
)
|
||||
retry_data = retry_res.get_json()
|
||||
from app.services.shipping_notice import decision_workflow
|
||||
|
||||
with app.app_context():
|
||||
retry_data = decision_workflow.submit_decision({"task_id": task_id, "decision": "retry_rpa"})
|
||||
assert retry_data["status"] == "running"
|
||||
assert retry_data.get("data", {}).get("rpa_runtime", {}).get("mode") in {"browser", "mock"}
|
||||
|
||||
@@ -1750,7 +1783,7 @@ def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt
|
||||
task.step_payload_json = {
|
||||
"rpa_inventory_source": {
|
||||
"source_code": "DSV360_AWSDU",
|
||||
"source_type": "dsv360",
|
||||
"connector_type": "dsv360",
|
||||
"display_name": "DSV 360 / Dublin / AWSDU - Prod (JDA)",
|
||||
"entry_url": "https://s360.dbschenker.com/",
|
||||
"query": {"program_label": "AWSDU - Prod (JDA)", "owner_code": "CADU-0000000100"},
|
||||
@@ -1813,7 +1846,7 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
|
||||
task.step_payload_json = {
|
||||
"rpa_inventory_source": {
|
||||
"source_code": "DSV360_AWSDU",
|
||||
"source_type": "dsv360",
|
||||
"connector_type": "dsv360",
|
||||
"display_name": "DSV 360 / Dublin / AWSDU - Prod (JDA)",
|
||||
"entry_url": "https://s360.dbschenker.com/",
|
||||
"query": {"program_label": "AWSDU - Prod (JDA)", "owner_code": "CADU-0000000100"},
|
||||
@@ -1833,12 +1866,10 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
retry_res = client.post(
|
||||
"/api/shipping-notice/tools/submit_decision",
|
||||
headers=headers,
|
||||
json={"task_id": task_id, "decision": "retry_rpa"},
|
||||
)
|
||||
retry_data = retry_res.get_json()
|
||||
from app.services.shipping_notice import decision_workflow
|
||||
|
||||
with app.app_context():
|
||||
retry_data = decision_workflow.submit_decision({"task_id": task_id, "decision": "retry_rpa"})
|
||||
assert retry_data["status"] == "running"
|
||||
assert retry_data.get("data", {}).get("rpa", {}).get("attempts") == 1
|
||||
|
||||
@@ -1894,7 +1925,7 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
|
||||
task.step_payload_json = {
|
||||
"rpa_inventory_source": {
|
||||
"source_code": "DSV360_AWSDU",
|
||||
"source_type": "dsv360",
|
||||
"connector_type": "dsv360",
|
||||
"display_name": "DSV 360 / Dublin / AWSDU - Prod (JDA)",
|
||||
"entry_url": "https://s360.dbschenker.com/",
|
||||
"query": {"program_label": "AWSDU - Prod (JDA)", "owner_code": "CADU-0000000100"},
|
||||
|
||||
Reference in new issue
Block a user