Fixed recipes_nestings_resolved recursive serving calculation (fixes #2361)

This commit is contained in:
Bernd Bestel 2025-01-13 21:37:16 +01:00
parent c8ccc0b529
commit cc40344845
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 28 additions and 1 deletions

View File

@ -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

26
migrations/0243.sql Normal file
View File

@ -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;