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

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-19 12:46:09 +08:00
1 parent ca4b9a15c5
commit 1d3f73d3b9
1 file changed
+23 -2
+23 -2
View File
@@ -145,6 +145,23 @@ def get_material(
return q.first() 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( def create_material(
db: Session, db: Session,
*, *,
@@ -160,6 +177,7 @@ def create_material(
remark: Optional[str] = None, remark: Optional[str] = None,
user_id: Optional[str] = None, user_id: Optional[str] = None,
create_dept_id: str = "", create_dept_id: str = "",
commit: bool = True,
) -> BizQcMaterial: ) -> BizQcMaterial:
code = (material_code or "").strip() code = (material_code or "").strip()
if not code: if not code:
@@ -190,8 +208,11 @@ def create_material(
del_flag=0, del_flag=0,
) )
db.add(obj) db.add(obj)
db.commit() if commit:
db.refresh(obj) db.commit()
db.refresh(obj)
else:
db.flush()
return obj return obj