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