Number of serves affects purchase amount
This commit is contained in:
parent
794c32c2df
commit
0aa1d07231
1 changed files with 10 additions and 1 deletions
|
|
@ -1,10 +1,19 @@
|
||||||
import units from '@/units.js';
|
import units from '@/units.js';
|
||||||
|
|
||||||
|
function scaleFactor(meal, recipe) {
|
||||||
|
const numYield = recipe.serves;
|
||||||
|
const numConsumers = meal.consumers.length;
|
||||||
|
|
||||||
|
return numConsumers / numYield;
|
||||||
|
}
|
||||||
|
|
||||||
export function mealToShoppingListSources(meal) {
|
export function mealToShoppingListSources(meal) {
|
||||||
const sources = [];
|
const sources = [];
|
||||||
for (const recipe of meal.recipes) {
|
for (const recipe of meal.recipes) {
|
||||||
|
const scale = scaleFactor(meal, recipe);
|
||||||
for (const ingredient of recipe.ingredients) {
|
for (const ingredient of recipe.ingredients) {
|
||||||
sources.push({ ingredient, meal, recipe, });
|
const quantity = ingredient.quantity * scale;
|
||||||
|
sources.push({ meal, recipe, ingredient: { ...ingredient, quantity, }, });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue