implement delete order

This commit is contained in:
2025-11-02 18:41:12 +02:00
parent 025236013f
commit 8a2bad78fa
2 changed files with 53 additions and 2 deletions

View File

@@ -142,7 +142,13 @@ class OrdersPage:
),
self.products_column,
ft.Divider(),
self.buttons_state
ft.Row(
[
self.buttons_state,
ft.Button("Sterge", icon = ft.Icons.DELETE, on_click=self.on_order_delete_btn_click)
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
)
],
expand=True
)
@@ -176,6 +182,37 @@ class OrdersPage:
]
)
self.delete_order_dialog = ft.AlertDialog(
title=ft.Text("Sertgeti?"),
actions=[
ft.FilledButton(
"Da",
on_click=self.on_confirm_delete_order
),
ft.FilledButton(
"Nu",
on_click=self.on_cancel_delete_order_btn_click,
bgcolor=ft.Colors.GREY
)
]
)
def on_order_delete_btn_click(self, e):
self.page.open(self.delete_order_dialog)
def on_confirm_delete_order(self, e):
self.orders.remove_order(self.selected_order['id'])
self.all_orders = self.orders.get_orders()[::-1]
self.oll_orders_list.controls = self.create_list(self.all_orders, self.on_order_click)
self.oll_orders_list.update()
self.selected_order = None
self.order_details_placeholder.content = None
self.order_details_placeholder.update()
self.page.close(self.delete_order_dialog)
def on_cancel_delete_order_btn_click(self, e):
self.page.close(self.delete_order_dialog)
def on_radio_value_change(self, e):
self.page.open(self.change_state_dialog)

View File

@@ -164,9 +164,23 @@ class Orders:
return []
def remove_product_from_order(self, order_id, product_id):
with sqlite3.connect(self.db_path) as conn:
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''
DELETE FROM orders_products WHERE orders_id=? and product_id=?;
''', (order_id, product_id))
conn.commit()
def remove_order(self, order_id):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''
DELETE FROM orders_products WHERE orders_id=?;
''', (order_id,))
conn.commit()
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''
DELETE FROM orders WHERE id=?;
''', (order_id,))
conn.commit()