feat(backend): filter QC material batches by stockStatus.
Support available (remaining_qty > 0) and exhausted (remaining_qty = 0) on the batch list API. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0f461851b5
commit
f014e3f88a
2 files changed
+9
No files matched your search
@@ -1624,6 +1624,7 @@ async def list_qc_material_batches(
|
||||
keyword: Optional[str] = None,
|
||||
materialId: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
stockStatus: Optional[str] = None,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code("biz:qcMaterial:list")),
|
||||
):
|
||||
@@ -1636,6 +1637,7 @@ async def list_qc_material_batches(
|
||||
keyword=keyword,
|
||||
material_id=materialId,
|
||||
status=status,
|
||||
stock_status=stockStatus,
|
||||
tenant_no=tenant_no,
|
||||
user_info=user,
|
||||
)
|
||||
|
||||
@@ -10,6 +10,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.utils import generate_uuid
|
||||
from app.crud.qc_material import _dec, _fmt_dt, _is_enabled_status, _norm_status
|
||||
from app.crud.qc_material_batch_stock_status import normalize_batch_stock_status
|
||||
from app.models.qc_material import BizQcMaterial, BizQcMaterialStockBatch, BizQcMaterialUsage
|
||||
|
||||
|
||||
@@ -150,6 +151,7 @@ def list_batches(
|
||||
keyword: Optional[str] = None,
|
||||
material_id: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
stock_status: Optional[str] = None,
|
||||
tenant_no: Optional[str] = None,
|
||||
user_info=None,
|
||||
) -> Tuple[List[Dict[str, Any]], int]:
|
||||
@@ -184,6 +186,11 @@ def list_batches(
|
||||
st = (status or "").strip()
|
||||
if st in ("0", "1"):
|
||||
q0 = q0.filter(BizQcMaterial.status == st)
|
||||
mode = normalize_batch_stock_status(stock_status)
|
||||
if mode == "available":
|
||||
q0 = q0.filter(BizQcMaterialStockBatch.remaining_qty > 0)
|
||||
elif mode == "exhausted":
|
||||
q0 = q0.filter(BizQcMaterialStockBatch.remaining_qty == 0)
|
||||
if user_info:
|
||||
from app.core.data_scope import apply_data_scope
|
||||
|
||||
|
||||
Reference in new issue
Block a user