Fixed multi-nested recipe serving amount calculation (fixes #1806)

This commit is contained in:
Bernd Bestel 2022-03-03 17:38:51 +01:00
parent 54a8c331c2
commit 620f938065
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,7 @@
- Fixed that consuming recipes was possible when not all ingredients were in-stock (and this potentially consumed some of the in-stock ingredients; not matching the message "nothing removed")
- Fixed that the price of the "Produces product"-product, which is added to stock on consuming a recipe, was wrong (was the recipe total costs multiplied by the serving amount instead of only the recipe total costs)
- Fixed that calories of recipe ingredients were displayed with an indefinite number of decimal places
- Fixed that ingredient amounts were wrong for multi-nested (> 2 levels) recipes, when the included recipe used an serving amount other than 1
### Meal plan

26
migrations/0174.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,
CASE WHEN r1.level = 0 THEN rn.servings ELSE (SELECT servings FROM recipes_nestings WHERE recipe_id = r1.recipe_id AND includes_recipe_id = r1.includes_recipe_id) END 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;