Files
zkxw/backend/app/crud/qc_material_batch_stock_status.py
T
zlwuandCursor 0f461851b5 feat(backend): add QC material batch stockStatus helpers.
Normalize available/exhausted filter values and document remaining_qty matching for list filtering.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-18 09:36:33 +08:00

25 lines
890 B
Python

"""质检物料入库批次:按剩余数量过滤的语义辅助。"""
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