21 lines
792 B
Python
21 lines
792 B
Python
from __future__ import annotations
|
|
|
|
from app import db
|
|
from app.lab.db_guard import retry_locked
|
|
from app.lab.models import LabRecipeRation
|
|
from app.models import Recipe
|
|
|
|
|
|
@retry_locked
|
|
def ensure_empty_master(recipe_id: str, user_id: str = "system") -> dict:
|
|
recipe = Recipe.query.filter_by(id=recipe_id, is_deleted=False).first()
|
|
if recipe is None:
|
|
raise LookupError("Рецепт не найден")
|
|
existing = LabRecipeRation.query.filter_by(recipe_id=recipe_id, is_deleted=False).first()
|
|
if existing is not None:
|
|
return {"recipeId": recipe_id, "created": False}
|
|
header = LabRecipeRation(recipe_id=recipe_id, created_by=user_id, updated_by=user_id)
|
|
db.session.add(header)
|
|
db.session.commit()
|
|
return {"recipeId": recipe_id, "created": True}
|