Browse Source

Some small fixes

Eren Yilmaz 6 years ago
parent
commit
2146815188
1 changed files with 10 additions and 6 deletions
  1. 10 6
      model.py

+ 10 - 6
model.py

@@ -568,7 +568,7 @@ def delete_order(order_id, new_order_status):
             rowid
         FROM orders
         WHERE rowid = ?
-        ''', (order_id, new_order_status))
+        ''', (new_order_status, order_id,))
 
     cursor.execute('''
         DELETE FROM orders
@@ -860,11 +860,9 @@ def drop_expired_orders():
         ''')
 
     data = cursor.fetchall()
-
-    cursor.execute('''
-        DELETE FROM orders 
-        WHERE expiry_dt < DATETIME('now')
-        ''')
+    for order in data:
+        order_id = order[0]
+        delete_order(order_id, 'Expired')
 
     return data
 
@@ -1014,6 +1012,12 @@ def delete_ownable(ownable_id):
             SELECT rowid FROM ownership WHERE ownable_id = ?)
         ''', (ownable_id,))
 
+    cursor.execute('''
+        DELETE FROM orders_history
+        WHERE ownership_id IN (
+            SELECT rowid FROM ownership WHERE ownable_id = ?)
+        ''', (ownable_id,))
+
     # only delete empty ownerships
     cursor.execute('''
         DELETE FROM ownership