Update app.py
Browse files
app.py
CHANGED
@@ -121,15 +121,13 @@ def login():
|
|
121 |
|
122 |
@app.route('/order_summary')
|
123 |
def order_summary():
|
124 |
-
email = session.get('user_email')
|
125 |
|
126 |
if not email:
|
127 |
-
|
128 |
-
return "User not logged in", 400
|
129 |
|
130 |
try:
|
131 |
-
|
132 |
-
|
133 |
query = f"""
|
134 |
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
|
135 |
FROM Order__c
|
@@ -140,27 +138,27 @@ def order_summary():
|
|
140 |
result = sf.query(query)
|
141 |
|
142 |
if not result.get("records"):
|
143 |
-
print("No order found for this user.")
|
144 |
return "No order found for this user", 400
|
145 |
|
146 |
-
order = result["records"][0]
|
147 |
-
order_details = order.get("Order_Details__c", "")
|
148 |
|
|
|
|
|
149 |
order_items = []
|
150 |
|
151 |
if order_details:
|
152 |
-
print("Processing order details...")
|
153 |
for line in order_details.split('\n'):
|
154 |
item_parts = line.split('|')
|
155 |
if len(item_parts) >= 5:
|
156 |
item_name = item_parts[0].strip()
|
157 |
item_name_cleaned = ' '.join(item_name.split(' ')[:-1]).strip()
|
158 |
|
|
|
159 |
menu_query = f"""
|
160 |
-
SELECT Name, Price__c, Image1__c, Ingredient_1__r.Ingredient_Name__c,
|
161 |
-
Ingredient_1__r.Ingredient_Image__c, Ingredient_1__r.Health_Benefits__c,
|
162 |
-
Ingredient_1__r.Fun_Facts__c, Ingredient_2__r.Ingredient_Name__c,
|
163 |
-
Ingredient_2__r.Ingredient_Image__c, Ingredient_2__r.Health_Benefits__c,
|
164 |
Ingredient_2__r.Fun_Facts__c
|
165 |
FROM Menu_Item__c
|
166 |
WHERE Name = '{item_name_cleaned}'
|
@@ -188,16 +186,8 @@ def order_summary():
|
|
188 |
}
|
189 |
]
|
190 |
})
|
191 |
-
print(f"Item found in menu: {item_name_cleaned}")
|
192 |
-
else:
|
193 |
-
print(f"Item not found in menu: {item_name_cleaned}")
|
194 |
-
|
195 |
-
if not order_items:
|
196 |
-
print("No items found in order details.")
|
197 |
-
else:
|
198 |
-
print(f"Total items extracted: {len(order_items)}")
|
199 |
|
200 |
-
# Pass
|
201 |
return render_template(
|
202 |
'reward_status.html',
|
203 |
order_items=order_items
|
@@ -207,6 +197,7 @@ def order_summary():
|
|
207 |
print(f"Error querying Salesforce: {str(e)}")
|
208 |
return f"Error querying Salesforce: {str(e)}", 500
|
209 |
|
|
|
210 |
@app.route("/logout")
|
211 |
def logout():
|
212 |
# Retrieve table number before clearing session
|
|
|
121 |
|
122 |
@app.route('/order_summary')
|
123 |
def order_summary():
|
124 |
+
email = session.get('user_email') # Get user email from session
|
125 |
|
126 |
if not email:
|
127 |
+
return "User not logged in", 400 # Redirect if no email found in session
|
|
|
128 |
|
129 |
try:
|
130 |
+
# Query Salesforce to get order details
|
|
|
131 |
query = f"""
|
132 |
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
|
133 |
FROM Order__c
|
|
|
138 |
result = sf.query(query)
|
139 |
|
140 |
if not result.get("records"):
|
|
|
141 |
return "No order found for this user", 400
|
142 |
|
143 |
+
order = result["records"][0] # Get the most recent order
|
|
|
144 |
|
145 |
+
# Process order details
|
146 |
+
order_details = order.get("Order_Details__c", "")
|
147 |
order_items = []
|
148 |
|
149 |
if order_details:
|
|
|
150 |
for line in order_details.split('\n'):
|
151 |
item_parts = line.split('|')
|
152 |
if len(item_parts) >= 5:
|
153 |
item_name = item_parts[0].strip()
|
154 |
item_name_cleaned = ' '.join(item_name.split(' ')[:-1]).strip()
|
155 |
|
156 |
+
# Query Menu_Item to get item details (price, ingredients)
|
157 |
menu_query = f"""
|
158 |
+
SELECT Name, Price__c, Image1__c, Ingredient_1__r.Ingredient_Name__c,
|
159 |
+
Ingredient_1__r.Ingredient_Image__c, Ingredient_1__r.Health_Benefits__c,
|
160 |
+
Ingredient_1__r.Fun_Facts__c, Ingredient_2__r.Ingredient_Name__c,
|
161 |
+
Ingredient_2__r.Ingredient_Image__c, Ingredient_2__r.Health_Benefits__c,
|
162 |
Ingredient_2__r.Fun_Facts__c
|
163 |
FROM Menu_Item__c
|
164 |
WHERE Name = '{item_name_cleaned}'
|
|
|
186 |
}
|
187 |
]
|
188 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
+
# Pass order_items to the template
|
191 |
return render_template(
|
192 |
'reward_status.html',
|
193 |
order_items=order_items
|
|
|
197 |
print(f"Error querying Salesforce: {str(e)}")
|
198 |
return f"Error querying Salesforce: {str(e)}", 500
|
199 |
|
200 |
+
|
201 |
@app.route("/logout")
|
202 |
def logout():
|
203 |
# Retrieve table number before clearing session
|