@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.lab.dto.ration import ExecutionLineSnapshot, ExecutionSnapshot
|
||||
from app.models import Ingredient, Recipe
|
||||
|
||||
|
||||
def load_execution(recipe_id: str) -> ExecutionSnapshot:
|
||||
recipe = Recipe.query.filter_by(id=recipe_id, is_deleted=False).first()
|
||||
if recipe is None:
|
||||
raise LookupError("Рецепт не найден")
|
||||
heads = int(recipe.heads_per_trip or 1)
|
||||
ingredients = (
|
||||
Ingredient.query.filter_by(recipe_id=recipe_id, is_deleted=False)
|
||||
.order_by(Ingredient.order)
|
||||
.all()
|
||||
)
|
||||
lines = []
|
||||
for ing in ingredients:
|
||||
wph = float(ing.weight_per_head or 0)
|
||||
lines.append(
|
||||
ExecutionLineSnapshot(
|
||||
ingredient_id=ing.id,
|
||||
component_id=ing.component_id,
|
||||
name=ing.name,
|
||||
weight_per_head=wph,
|
||||
daily_kg_total=wph * heads,
|
||||
)
|
||||
)
|
||||
return ExecutionSnapshot(recipe_id=recipe_id, heads_per_trip=heads, lines=tuple(lines))
|
||||
Reference in New Issue
Block a user