"""Рецепт для экрана оператора загрузки (весы / дублёр) — с overlay «План на день».""" from __future__ import annotations from datetime import date as date_cls from typing import Any from app.models import Recipe def plan_ingredients_for_loading( recipe: Recipe, *, plan_date: str | None = None ) -> list[dict[str, Any]]: """Ингредиенты с весами плана на день, как на киоске тракториста (без пропущенных).""" from app.routes.recipes import _serialize_recipe resolved = (plan_date or date_cls.today().isoformat())[:10] payload = _serialize_recipe(recipe, plan_date=resolved, exclude_skipped=True) rows: list[dict[str, Any]] = [] for ing in payload.get("ingredients") or []: rows.append( { "id": ing.get("id"), "name": (ing.get("name") or "—").strip() or "—", "amount": float(ing.get("amount") or 0), "order": int(ing.get("order") or 0), } ) rows.sort(key=lambda row: (row["order"], str(row.get("id") or ""))) return rows