|
|
@@ -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
|
|
|
|
|
|
|