]> apps.delaporte.us Git - matrix-shop-bot.git/blobdiff - matrix_shop_bot/db.py
Fix for clear command
[matrix-shop-bot.git] / matrix_shop_bot / db.py
index 60339ee13e9d290c71d6ea395046b733a63502d2..278d4a15b8e8b75bce37636a496af4efcd967975 100644 (file)
@@ -183,13 +183,20 @@ class Data():
         return results
 
 
         return results
 
 
-    def clear_list(self, store_id, clear_all=False):
+    def clear_list(self, store_name, clear_all=False):
+        results = []
         with Session(self.engine) as session:
         with Session(self.engine) as session:
-            store = session.exec(_get_with_id(Store, store_id)).first()
+            store = session.exec(_get_with_name(Store, store_name)).first()
+            if not store:
+                return [f'Store {store_name} not found.']
+
             for item in store.shopping_list:
                 if clear_all or item.purchase_date:
                     session.delete(item)
             for item in store.shopping_list:
                 if clear_all or item.purchase_date:
                     session.delete(item)
+
             session.commit()
             session.commit()
+            results = store.get_pretty_shopping_list()
+        return results
 
     def get_stores(self):
         with Session(self.engine) as session:
 
     def get_stores(self):
         with Session(self.engine) as session: