- receipt→inbound 三件套改名(回调桥/文件门禁/触发服务),回调链幂等去重,迁移 tt14 同步台账键与测试基建 - 库存解析用途分层 onhand/inbound/outbound(迁移 tt15):解析档案、文件存储与下载名按用途隔离,管理端表单同步 - 「成熟」概念退役(迁移 tt16):数据无成熟属性,日期边界由调用方入参严格判定 - backlog 新增重解析服务,在途重识别投影 processing,EML 父项不再停留处理中 - 收料 RPA 回调/归档/排程链路同步改名挂点,运维脚本复位假完成状态 - 文档随批:ADR 0003 模块边界决策、10-15/10-16 计划与设计、调拨文档族与 demand/tec/funclist - 同步 chat/errors 文案四语言、调拨前端卡片与 e2e、测试全家
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_inbound_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 inbound quantity: {value!r}") from exc
|
|
if quantity <= 0:
|
|
raise QuantityValidationError(f"inbound 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(inbound_quantity: Any, external_quantity: Any | None) -> str:
|
|
"""按严格相等规则分类数量匹配结果。
|
|
|
|
Args:
|
|
inbound_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(inbound_quantity, external_quantity):
|
|
return MATCH_EXECUTABLE
|
|
return MATCH_QUANTITY_MISMATCH
|