File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -81,10 +81,23 @@ def add_item_to_list(self, ingredient: Ingredient) -> None:
81
81
self .log .debug (f"Adding ingredient to Bring: { ingredient } " )
82
82
83
83
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 )
85
91
else :
86
92
self .bring .saveItem (self .list_uuid , ingredient .food )
87
93
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
+
88
101
def notify_users_about_changes_in_list (self ) -> None :
89
102
self .log .debug ("Notifying users about changes in shopping list" )
90
103
self .bring .notify (self .list_uuid , BringNotificationType .CHANGED_LIST )
You can’t perform that action at this time.
0 commit comments