Skip to content

Commit f30523f

Browse files
committed
Allow adding an ingredient multiple times
1 parent e4f83cf commit f30523f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

source/bring_handler.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,23 @@ def add_item_to_list(self, ingredient: Ingredient) -> None:
8181
self.log.debug(f"Adding ingredient to Bring: {ingredient}")
8282

8383
if ingredient.specification:
84-
self.bring.saveItem(self.list_uuid, ingredient.food, ingredient.specification)
84+
if self.check_if_food_is_already_in_list(ingredient.food):
85+
self.log.info(
86+
f"The food {ingredient.food} is already in the list. Adding its specification in the title"
87+
)
88+
self.bring.saveItem(self.list_uuid, f"{ingredient.food} ({ingredient.specification})")
89+
else:
90+
self.bring.saveItem(self.list_uuid, ingredient.food, ingredient.specification)
8591
else:
8692
self.bring.saveItem(self.list_uuid, ingredient.food)
8793

94+
def check_if_food_is_already_in_list(self, food: str) -> bool:
95+
all_saved_foods = self.bring.getItems(self.list_uuid)["purchase"]
96+
for saved_food in all_saved_foods:
97+
if saved_food["name"].lower() == food.lower():
98+
return True
99+
return False
100+
88101
def notify_users_about_changes_in_list(self) -> None:
89102
self.log.debug("Notifying users about changes in shopping list")
90103
self.bring.notify(self.list_uuid, BringNotificationType.CHANGED_LIST)

0 commit comments

Comments
 (0)