Интегрирован wesp в сайт
CI / quality (push) Canceled after 0s

This commit is contained in:
влад
2026-07-17 12:57:18 +03:00
parent 5dfa06ddbe
commit 355c0ef9f1
883 changed files with 194576 additions and 177 deletions
@@ -0,0 +1,40 @@
from __future__ import annotations
from app.lab.models import LabRationLine
def find_rations_by_component(component_id: str) -> list[str]:
"""Recipe IDs с не удалёнными строками рациона, использующими component."""
if not component_id:
return []
rows = (
LabRationLine.query.filter_by(component_id=component_id, is_deleted=False)
.with_entities(LabRationLine.recipe_id)
.distinct()
.all()
)
return sorted({str(r[0]) for r in rows if r[0]})
def recalculate_rations(recipe_ids: list[str], user_id: str = "system") -> dict:
from app.lab.commands.recalculate import recalculate_ration
ok: list[str] = []
failed: dict[str, str] = {}
results: dict[str, dict] = {}
for recipe_id in recipe_ids:
try:
results[recipe_id] = recalculate_ration(recipe_id, user_id)
ok.append(recipe_id)
except Exception as exc:
failed[recipe_id] = str(exc)
return {"ok": ok, "failed": failed, "results": results}
def on_component_nutrients_changed(component_id: str, user_id: str = "system") -> dict:
"""Найти и пересчитать все рационы с данным компонентом (для будущего UI)."""
recipe_ids = find_rations_by_component(component_id)
if not recipe_ids:
return {"recipeIds": [], "ok": [], "failed": {}}
report = recalculate_rations(recipe_ids, user_id)
return {"recipeIds": recipe_ids, **report}