feat(backend): support non-committing qc material create and lookup by code
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ca4b9a15c5
commit
1d3f73d3b9
1 file changed
+23
-2
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user