From 6fd9cf0d8c030b21a55f36023b7bcbdf1353bf54 Mon Sep 17 00:00:00 2001 From: tourn Date: Fri, 20 Nov 2020 15:22:58 +0100 Subject: [PATCH] Use serving count in shopping list --- cookbook/templates/meal_plan.html | 2 +- cookbook/templates/shopping_list.html | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cookbook/templates/meal_plan.html b/cookbook/templates/meal_plan.html index 81940cec8..ba6e24597 100644 --- a/cookbook/templates/meal_plan.html +++ b/cookbook/templates/meal_plan.html @@ -577,7 +577,7 @@ id: Math.round(Math.random() * 1000) + 10000, recipe: recipe.id, recipe_name: recipe.name, - recipe_multiplier: (this.new_note_multiplier > 1) ? this.new_note_multiplier : 1, + recipe_multiplier: (this.new_note_multiplier > 1) ? this.new_note_multiplier : recipe.servings, title: this.new_note_title, note: this.new_note_text, is_new: true diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html index c84d1b9f6..3f55ff0ef 100644 --- a/cookbook/templates/shopping_list.html +++ b/cookbook/templates/shopping_list.html @@ -349,7 +349,12 @@ multiplier_cache() { let cache = {} this.shopping_list.recipes.forEach((r) => { - cache[r.id] = !(Number.isNaN(r.multiplier)) ? parseFloat(r.multiplier) : 1 + let multiplier = r.servings; + if(!Number.isNaN(r.multiplier)){ + multiplier = parseFloat(r.multiplier) + } + cache[r.id] = multiplier / r.servings; + }) return cache }, @@ -621,7 +626,8 @@ "id": Math.random() * 1000, "recipe": recipe.id, "recipe_name": recipe.name, - "multiplier": multiplier + "multiplier": multiplier, + "servings": recipe.servings, } this.shopping_list.recipes.push(slr)