Skip to content

Commit

Permalink
Allow adding an ingredient multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
felixschndr committed Dec 16, 2024
1 parent 133c730 commit 3bb5a65
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion source/bring_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,23 @@ def add_item_to_list(self, ingredient: Ingredient) -> None:
self.log.debug(f"Adding ingredient to Bring: {ingredient}")

if ingredient.specification:
self.bring.saveItem(self.list_uuid, ingredient.food, ingredient.specification)
if self.check_if_food_is_already_in_list(ingredient.food):
self.log.info(
f"The food {ingredient.food} is already in the list. Adding its specification in the title"
)
self.bring.saveItem(self.list_uuid, f"{ingredient.food} ({ingredient.specification})")
else:
self.bring.saveItem(self.list_uuid, ingredient.food, ingredient.specification)
else:
self.bring.saveItem(self.list_uuid, ingredient.food)

def check_if_food_is_already_in_list(self, food: str) -> bool:
all_saved_foods = self.bring.getItems(self.list_uuid)["purchase"]
for saved_food in all_saved_foods:
if saved_food["name"].lower() == food.lower():
return True
return False

def notify_users_about_changes_in_list(self) -> None:
self.log.debug("Notifying users about changes in shopping list")
self.bring.notify(self.list_uuid, BringNotificationType.CHANGED_LIST)

0 comments on commit 3bb5a65

Please sign in to comment.