pytest shopping list from recipe methods
This commit is contained in:
@ -106,35 +106,5 @@ def auto_add_shopping(sender, instance=None, created=False, weak=False, **kwargs
|
||||
'created_by': user,
|
||||
'servings': instance.servings
|
||||
}
|
||||
recipe_ingredients = Ingredient.objects.filter(step__recipe=instance.recipe, space=space)
|
||||
if exclude_onhand := user.userpreference.mealplan_autoexclude_onhand:
|
||||
recipe_ingredients = recipe_ingredients.exclude(food__on_hand=True)
|
||||
if related := user.userpreference.mealplan_autoinclude_related:
|
||||
# TODO: add levels of related recipes to use when auto-adding mealplans
|
||||
related_recipes = instance.recipe.get_related_recipes()
|
||||
# dont' add recipes that are going to have their recipes added to the shopping list
|
||||
kwargs['ingredients'] = recipe_ingredients.exclude(food__recipe__in=related_recipes).values_list('id', flat=True)
|
||||
else:
|
||||
kwargs['ingredients'] = recipe_ingredients.values_list('id', flat=True)
|
||||
|
||||
list_recipe = list_from_recipe(**kwargs)
|
||||
if related:
|
||||
servings_factor = Decimal(instance.servings / instance.recipe.servings)
|
||||
kwargs['list_recipe'] = list_recipe
|
||||
food_recipes = recipe_ingredients.filter(food__recipe__in=related_recipes).values('food__recipe', 'amount')
|
||||
|
||||
for recipe in related_recipes:
|
||||
kwargs['ingredients'] = []
|
||||
if exclude_onhand:
|
||||
kwargs['ingredients'] = Ingredient.objects.filter(step__recipe=recipe, food__on_hand=False, space=space).values_list('id', flat=True)
|
||||
kwargs['recipe'] = recipe
|
||||
|
||||
# assume related recipes are intended to be 'full sized' to parent recipe
|
||||
# Recipe1 (servings:4) includes StepRecipe2(servings:2) a Meal Plan serving size of 8 would assume 4 servings of StepRecipe2
|
||||
if recipe.id in [x['food__recipe'] for x in food_recipes if x['food__recipe'] == recipe.id]:
|
||||
kwargs['servings'] = Decimal(recipe.servings) * sum([x['amount'] for x in food_recipes if x['food__recipe'] == recipe.id]) * servings_factor
|
||||
else:
|
||||
# TODO: When modifying step recipes to allow serving size - will need to update this
|
||||
kwargs['servings'] = Decimal(recipe.servings) * servings_factor
|
||||
|
||||
list_from_recipe(**kwargs, append=True)
|
||||
|
Reference in New Issue
Block a user