mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Fixed multi-nested recipe serving amount calculation (fixes #1806)
This commit is contained in:
parent
54a8c331c2
commit
620f938065
@ -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
26
migrations/0174.sql
Normal 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;
|
Loading…
x
Reference in New Issue
Block a user