- 退役 erp_adapter/gateway_adapter:外部查询/写经 capability_client 走集成连接器,端点凭据与并发超时由客户端实例管理 - 域能力代码注册 capabilities:入参出参 Schema、幂等语义与读写标志随域代码版本化,组合根 create_app 幂等注册 - 新增调拨业务类型 transfer_type(在途仓至HUB/HUB维修出/HUB间)冻结枚举,迁移落 CheckConstraint 数据库兜底 - 外部仓库映射新增 in_transit_warehouse_code 拨出库位来源,管理端库存映射页同步维护 - 单据命名外部化:erp_* 字段与索引改称 external_*,单据号格式交由连接器映射,测试数据同步换牌 - 收料归档文件可用性判定收敛 receipt_file_gate 单一事实来源(当天抓取/保留期/清理态) - 同步 chat 调拨卡片、useChatTransfer、e2e、全套服务/API/Job 测试与域文档
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
"""在途调拨严格数量门禁。
|
|
|
|
用途:实现"收料数量 == 外部系统 账面库存 才可执行"的精确匹配规则,
|
|
禁止部分调拨、数量容差与隐式截断。
|
|
依赖:标准库 decimal。
|
|
逻辑:所有比较基于 Decimal 精确语义;非法数量(0/负数/非数字)在解析层拒绝。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from decimal import Decimal, InvalidOperation
|
|
from typing import Any
|
|
|
|
# 匹配结果
|
|
MATCH_EXECUTABLE = "executable"
|
|
MATCH_QUANTITY_MISMATCH = "blocked_quantity_mismatch"
|
|
MATCH_INVENTORY_NOT_FOUND = "blocked_inventory_not_found"
|
|
|
|
|
|
class QuantityValidationError(ValueError):
|
|
"""收料数量非法(0、负数、非数字)。"""
|
|
|
|
|
|
def validate_receipt_quantity(value: Any) -> Decimal:
|
|
"""校验并归一化收料数量。
|
|
|
|
Args:
|
|
value: 数字或数字字符串。
|
|
Returns:
|
|
归一化后的 Decimal。
|
|
Raises:
|
|
QuantityValidationError: 非数字、0 或负数。
|
|
"""
|
|
try:
|
|
quantity = Decimal(str(value))
|
|
except (InvalidOperation, ValueError) as exc:
|
|
raise QuantityValidationError(f"invalid receipt quantity: {value!r}") from exc
|
|
if quantity <= 0:
|
|
raise QuantityValidationError(f"receipt quantity must be positive: {value!r}")
|
|
return quantity
|
|
|
|
|
|
def strict_quantities_equal(left: Any, right: Any) -> bool:
|
|
"""Decimal 精确相等比较(1.0 == 1.00)。"""
|
|
return Decimal(str(left)) == Decimal(str(right))
|
|
|
|
|
|
def classify_quantity_match(receipt_quantity: Any, external_quantity: Any | None) -> str:
|
|
"""按严格相等规则分类数量匹配结果。
|
|
|
|
Args:
|
|
receipt_quantity: 收料数量。
|
|
external_quantity: 外部系统 账面库存;None 表示无库存。
|
|
Returns:
|
|
'executable' | 'blocked_quantity_mismatch' | 'blocked_inventory_not_found'。
|
|
"""
|
|
if external_quantity is None:
|
|
return MATCH_INVENTORY_NOT_FOUND
|
|
if strict_quantities_equal(receipt_quantity, external_quantity):
|
|
return MATCH_EXECUTABLE
|
|
return MATCH_QUANTITY_MISMATCH
|