mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-23 18:29:23 -05:00
default list when adding trough mealplan/recipe
This commit is contained in:
@@ -177,8 +177,9 @@ class RecipeShoppingEditor():
|
||||
existing = self._shopping_list_recipe.entries.filter(ingredient__in=ingredients).values_list('ingredient__pk', flat=True)
|
||||
add_ingredients = ingredients.exclude(id__in=existing)
|
||||
|
||||
entries = []
|
||||
for i in [x for x in add_ingredients if x.food]:
|
||||
ShoppingListEntry.objects.create(
|
||||
entry = ShoppingListEntry(
|
||||
list_recipe=self._shopping_list_recipe,
|
||||
food=i.food,
|
||||
unit=i.unit,
|
||||
@@ -187,6 +188,12 @@ class RecipeShoppingEditor():
|
||||
created_by=self.created_by,
|
||||
space=self.space,
|
||||
)
|
||||
entries.append(entry)
|
||||
|
||||
ShoppingListEntry.objects.bulk_create(entries)
|
||||
for e in entries:
|
||||
if e.food.shopping_lists.count() > 0:
|
||||
e.shopping_lists.set(e.food.shopping_lists.all())
|
||||
|
||||
# deletes shopping list entries not in ingredients list
|
||||
def _delete_ingredients(self, ingredients=None):
|
||||
|
||||
@@ -1992,8 +1992,7 @@ class ShoppingListRecipeViewSet(LoggingMixin, viewsets.ModelViewSet):
|
||||
if serializer.is_valid():
|
||||
entries = []
|
||||
for e in serializer.validated_data['entries']:
|
||||
entries.append(
|
||||
ShoppingListEntry(
|
||||
entry = ShoppingListEntry(
|
||||
list_recipe_id=obj.pk,
|
||||
amount=e['amount'],
|
||||
unit_id=e['unit_id'],
|
||||
@@ -2002,9 +2001,13 @@ class ShoppingListRecipeViewSet(LoggingMixin, viewsets.ModelViewSet):
|
||||
created_by_id=request.user.id,
|
||||
space_id=request.space.id,
|
||||
)
|
||||
)
|
||||
entries.append(entry)
|
||||
|
||||
ShoppingListEntry.objects.bulk_create(entries)
|
||||
for e in entries:
|
||||
if e.food.shopping_lists.count() > 0:
|
||||
e.shopping_lists.set(e.food.shopping_lists.all())
|
||||
|
||||
ConnectorManager.add_work(ActionType.CREATED, *entries)
|
||||
return Response(serializer.validated_data)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user