diff --git a/changelog/77_UNRELEASED_xxxx-xx-xx.md b/changelog/77_UNRELEASED_xxxx-xx-xx.md index 4a64f406..f57d766c 100644 --- a/changelog/77_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/77_UNRELEASED_xxxx-xx-xx.md @@ -30,10 +30,11 @@ ### Recipes - Fixed that calories/costs of recipe ingredients were wrong when the ingredient option "Only check if any amount is in stock" was set and the on the ingredient used quantity unit was different from the product's QU stock +- Fixed that multi-nested recipes (at least 3 levels of "included recipes") resulted in wrong amounts/costs/calories calculated for the ingredients orginating in those nested recipes (also affected the meal plan) ### Meal plan -- xxx +- Fixed that amounts/costs/calories were wrong for recipes which had at least 2 levels of "included recipes" ### Chores diff --git a/migrations/0243.sql b/migrations/0243.sql new file mode 100644 index 00000000..0ee571d4 --- /dev/null +++ b/migrations/0243.sql @@ -0,0 +1,26 @@ +DROP VIEW recipes_nestings_resolved; +CREATE VIEW recipes_nestings_resolved +AS +WITH RECURSIVE r1(recipe_id, includes_recipe_id, includes_servings, level) +AS ( + SELECT + id AS recipe_id, + id AS includes_recipe_id, + 1 AS includes_servings, + 0 AS level + FROM recipes + + UNION ALL + + SELECT + rn.recipe_id, + r1.includes_recipe_id, + rn.servings * r1.includes_servings AS includes_servings, + r1.level + 1 AS level + FROM recipes_nestings rn, r1 r1 + WHERE rn.includes_recipe_id = r1.recipe_id +) +SELECT + *, + 1 AS id -- Dummy, LessQL needs an id column +FROM r1;