qc_material_batch_stock_status.py 890 B

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