From 1d3f73d3b95c643a9e5effb46e58b4d60b31d5d8 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Wed, 19 Aug 2026 12:46:09 +0800 Subject: [PATCH] feat(backend): support non-committing qc material create and lookup by code Co-authored-by: Cursor --- backend/app/crud/qc_material.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/backend/app/crud/qc_material.py b/backend/app/crud/qc_material.py index a284fe40..a7743859 100644 --- a/backend/app/crud/qc_material.py +++ b/backend/app/crud/qc_material.py @@ -145,6 +145,23 @@ def get_material( return q.first() +def get_material_by_code( + db: Session, material_code: str, *, tenant_no: str +) -> Optional[BizQcMaterial]: + code = (material_code or "").strip() + if not code: + return None + return ( + db.query(BizQcMaterial) + .filter( + BizQcMaterial.tenant_no == tenant_no, + BizQcMaterial.material_code == code, + BizQcMaterial.del_flag == 0, + ) + .first() + ) + + def create_material( db: Session, *, @@ -160,6 +177,7 @@ def create_material( remark: Optional[str] = None, user_id: Optional[str] = None, create_dept_id: str = "", + commit: bool = True, ) -> BizQcMaterial: code = (material_code or "").strip() if not code: @@ -190,8 +208,11 @@ def create_material( del_flag=0, ) db.add(obj) - db.commit() - db.refresh(obj) + if commit: + db.commit() + db.refresh(obj) + else: + db.flush() return obj