feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估

- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。
- 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。
- 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。
- 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。
- 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
hugo committed 2026-08-02 19:26:35 +08:00
1 parent cef3d5b26a
commit 3a9fbac2fc
226 files changed
+25010 -2098

No files matched your search

@@ -4,7 +4,8 @@ backend/app/services/shipping_notice/candidate_service.py
用途:提供订单候选的用户态查询、选择与重复决策能力;含 STP 严格建单门禁。
依赖:ShippingNoticeCandidate/Document/Intake、duplicate_detection、business_fingerprint。
逻辑:workspace API 调用本模块;所有写操作锁定 Candidate,并在字段变化后重算双指纹和重复状态;
仅严格门禁通过的 Candidate 可物化 Task(缺字段/低置信/缺证据/重复冲突 → 拒绝)。
仅严格门禁通过且客户已确认的 Candidate 可物化 Task
(缺字段/低置信/缺证据/重复冲突/客户未确认 → 拒绝)。
"""
from __future__ import annotations
@@ -65,10 +66,11 @@ def evaluate_candidate_stp_gate(candidate: ShippingNoticeCandidate) -> tuple[boo
def ensure_candidate_fulfillment_ready(candidate: ShippingNoticeCandidate) -> None:
"""
统一履约门禁:已接受、当前、无阻断;automatic 候选额外通过 STP 严格门禁。
统一履约门禁:已接受、当前、无阻断;建 Task 前客户必须已确认;
automatic 候选额外通过 STP 严格门禁。
Raises:
ConflictError: 接受态、选中态、版本、消费态或 STP 严格门禁失败。
ConflictError: 接受态、选中态、版本、消费态、客户未确认或 STP 严格门禁失败。
"""
if str(candidate.candidate_status or '') != 'accepted':
raise ConflictError(
@@ -86,6 +88,12 @@ def ensure_candidate_fulfillment_ready(candidate: ShippingNoticeCandidate) -> No
code='SHIPPING_NOTICE.CANDIDATE_REVIEW_REQUIRED',
message='订单候选仍有字段冲突或未完成审核',
)
# [STEP] 客户确认必须在创建 Task 之前,禁止依赖建单后 customer_review。
from app.services.shipping_notice.candidate_qualification_service import (
assert_customer_confirmed_before_task_create,
)
assert_customer_confirmed_before_task_create(candidate=candidate)
# [STEP] STP 严格门禁仅约束自动直通;人工确认建单已由复核草稿校验背书。
passed, reason_codes = evaluate_candidate_stp_gate(candidate)
if not passed:
@@ -237,7 +245,7 @@ def reject_candidate(*, user_id: int, candidate_no: str, reason: str | None = No
actor_type='user',
actor_id=user_id,
run_no=getattr(candidate, 'run_no', None) or None,
reason_code='manual_rejected',
reason_code='task_rejected_by_user',
before={'status': 'provisional'},
after={'status': 'rejected'},
)