| 123456789101112131415161718192021222324 |
- """质检物料入库批次:按剩余数量过滤的语义辅助。"""
- from __future__ import annotations
- from decimal import Decimal
- from typing import Any, Optional
- def normalize_batch_stock_status(stock_status: Optional[str]) -> Optional[str]:
- """返回 'available' | 'exhausted';全部 / 空 / 非法 → None(不加剩余数量条件)。"""
- s = (stock_status or "").strip().lower()
- if s in ("available", "exhausted"):
- return s
- return None
- def batch_matches_stock_status(remaining_qty: Any, stock_status: Optional[str]) -> bool:
- """纯函数判定(供单测);list_batches 用 SQL 等价条件。"""
- mode = normalize_batch_stock_status(stock_status)
- if mode is None:
- return True
- qty = Decimal(str(remaining_qty if remaining_qty is not None else 0))
- if mode == "available":
- return qty > 0
- return qty == 0
|