Files
syops/backend/app/services/in_transit_transfer/strategy.py
T
hugo 9f2b023a10 feat(in-transit-transfer): 打通ERP 写路径按票执行与已执行调拨单卡片入口
- 新增 TransferDocument 按票执行模型与单据号序列生成(document_id 独立模块,迁移 tt0d/tt8b)
- 发票行新增单位字段、matching_id 放宽可空,支持行与票两级执行口径(迁移 tt9c/tt1a)
- capability_client 新增 create_transfer 写契约与六态结果裁决,执行链补写前复查门禁
- 抽取/匹配/执行 Job 按 run/item/match 拆分并入 jobs store 队列,transfer 队列单实例 worker 配套本地启动脚本
- 首页新增「已执行调拨单」四统计卡入口与明细列表子视图,重查/重试/关闭/重新触发与筛选分页齐全
- 行评估新鲜度 TTL 从 10 分钟放宽为当日有效(86400s),跨日由文件版本对账门禁兜底
- 同步 chat/errors 文案四语言、测试全家与两份实施计划文档
2026-09-27 18:13:25 +08:00

66 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""在途调拨策略硬门禁。
用途:一期策略禁止部分数量调拨、数量容差与 外部系统 自动重试;
confirm_ttl_seconds 为纯展示阈值(默认 10 分钟 stale 徽标判定窗口,
不再作为执行门禁——2026-09-25 退役)。
依赖:app.core.errors.AppError、standard decimal。
逻辑:任何策略变体触碰三项禁令之一即抛 StrategyViolationError,
阻止发布/执行(fail-closed)。
"""
from __future__ import annotations
from dataclasses import dataclass
from decimal import Decimal
from app.core.errors import AppError
STRATEGY_VIOLATION_CODE = "TRANSFER.STRATEGY_VIOLATION"
DEFAULT_CONFIRM_TTL_SECONDS = 600 # 10 分钟
@dataclass(frozen=True)
class TransferStrategyPolicy:
"""调拨策略冻结快照;三项禁令默认关闭。"""
allow_partial: bool = False
quantity_tolerance: Decimal = Decimal("0")
allow_external_auto_retry: bool = False
# 纯展示阈值:行 stale 徽标(「库存数据已过期,请重查」提示)的判定窗口;
# 不再作为执行门禁(2026-09-25 退役)——防错由文件版本对账 + worker 写前
# 库存复查承担(见 execution_service)。
confirm_ttl_seconds: int = DEFAULT_CONFIRM_TTL_SECONDS
class StrategyViolationError(AppError):
"""策略触碰一期禁令。"""
def __init__(self, message: str, *, reason: str):
super().__init__(
code=STRATEGY_VIOLATION_CODE,
message=message,
http_status=409,
details={"reason": reason},
)
def validate_strategy(strategy: TransferStrategyPolicy) -> None:
"""校验策略是否违反一期硬门禁。
Args:
strategy: 待校验策略。
Raises:
StrategyViolationError: 开启部分调拨、非零容差或 外部系统 自动重试。
"""
if strategy.allow_partial:
raise StrategyViolationError("partial transfer is not supported in phase 1", reason="allow_partial")
if strategy.quantity_tolerance != Decimal("0"):
raise StrategyViolationError("quantity tolerance is not supported in phase 1", reason="quantity_tolerance")
if strategy.allow_external_auto_retry:
raise StrategyViolationError("External auto retry is forbidden in phase 1", reason="allow_external_auto_retry")
def default_strategy() -> TransferStrategyPolicy:
"""返回一期默认策略(全部禁令关闭,stale 展示阈值 600 秒)。"""
return TransferStrategyPolicy()