Create orders.py
Browse files- routes/orders.py +27 -0
routes/orders.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from utils.file_initializer import ORDERS_FILE, MENU_FILE
|
3 |
+
|
4 |
+
def add_to_order(table_id, customer_email, dish_name, spice_level, customizations):
|
5 |
+
menu = pd.read_excel(MENU_FILE)
|
6 |
+
orders = pd.read_excel(ORDERS_FILE)
|
7 |
+
dish = menu[menu["Dish Name"] == dish_name].iloc[0]
|
8 |
+
total_cost = dish["Price"]
|
9 |
+
order_details = f"{dish_name} ({spice_level}) {customizations}"
|
10 |
+
orders = orders.append(
|
11 |
+
{"Table ID": table_id, "Customer Email": customer_email, "Order Details": order_details, "Total Cost": total_cost},
|
12 |
+
ignore_index=True
|
13 |
+
)
|
14 |
+
orders.to_excel(ORDERS_FILE, index=False)
|
15 |
+
return f"{dish_name} added to order!"
|
16 |
+
|
17 |
+
def view_order(table_id, customer_email):
|
18 |
+
orders = pd.read_excel(ORDERS_FILE)
|
19 |
+
return orders[(orders["Table ID"] == table_id) & (orders["Customer Email"] == customer_email)]
|
20 |
+
|
21 |
+
def place_order(table_id, customer_email):
|
22 |
+
orders = pd.read_excel(ORDERS_FILE)
|
23 |
+
table_orders = orders[(orders["Table ID"] == table_id) & (orders["Customer Email"] == customer_email)]
|
24 |
+
if table_orders.empty:
|
25 |
+
return "No items in the order."
|
26 |
+
total_cost = table_orders["Total Cost"].sum()
|
27 |
+
return f"Order placed successfully! Total Cost: {total_cost}"
|