fix: Account for on hand items when adding a recipe to a shopping list (#7912)

Co-authored-by: Arsène Reymond <66876397+p0lycarpio@users.noreply.github.com>
This commit is contained in:
miahandArsène Reymond authored and GitHub committed 2026-08-27 11:39:23 +00:00
1 parent 2f6df9bb8c
commit 8d6027770c
1 file changed
+13
@@ -355,6 +355,8 @@ class ShoppingListService:
continue
if isinstance(ingredient.food, IngredientFood):
if self._is_on_hand(list_id, ingredient.food):
continue
food_id = ingredient.food.id
label_id = ingredient.food.label_id
else:
@@ -410,6 +412,15 @@ class ShoppingListService:
return list_items
def _is_on_hand(self, list_id: UUID4, food: IngredientFood) -> bool:
shopping_list = self.shopping_lists.get_one(list_id)
if shopping_list is None:
return False
household = self.repos.households.get_by_slug_or_id(shopping_list.household_id)
if household is None:
return False
return household.slug in food.households_with_ingredient_food
def add_recipe_ingredients_to_list(
self,
list_id: UUID4,
@@ -472,6 +483,8 @@ class ShoppingListService:
update_items: list[ShoppingListItemUpdateBulk] = []
delete_items: list[UUID4] = []
for item in shopping_list.list_items:
if item.food is not None and self._is_on_hand(list_id, item.food):
continue
found = False
refs = cast(list[ShoppingListItemRecipeRefOut], item.recipe_references)