Просмотр исходного кода

feat(backend): support non-committing qc material create and lookup by code

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 2 месяцев назад
Родитель
Сommit
1d3f73d3b9
1 измененных файлов с 23 добавлено и 2 удалено
  1. 23 2
      backend/app/crud/qc_material.py

+ 23 - 2
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