Update app.py
Browse files
app.py
CHANGED
@@ -119,6 +119,8 @@ def login():
|
|
119 |
|
120 |
return render_template("login.html")
|
121 |
|
|
|
|
|
122 |
@app.route('/order_summary')
|
123 |
def order_summary():
|
124 |
email = session.get('user_email')
|
@@ -156,6 +158,8 @@ def order_summary():
|
|
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,
|
@@ -165,30 +169,50 @@ def order_summary():
|
|
165 |
FROM Menu_Item__c
|
166 |
WHERE Name = '{item_name_cleaned}'
|
167 |
"""
|
|
|
|
|
168 |
menu_result = sf.query(menu_query)
|
|
|
169 |
|
170 |
if menu_result.get("records"):
|
171 |
menu_item = menu_result["records"][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
order_items.append({
|
173 |
"name": item_name_cleaned,
|
174 |
"price": menu_item.get("Price__c"),
|
175 |
"image_url": menu_item.get("Image1__c"),
|
176 |
-
"ingredients":
|
177 |
-
{
|
178 |
-
"name": menu_item['Ingredient_1__r']['Ingredient_Name__c'] if 'Ingredient_1__r' in menu_item else None,
|
179 |
-
"image": menu_item['Ingredient_1__r']['Ingredient_Image__c'] if 'Ingredient_1__r' in menu_item else None,
|
180 |
-
"health_benefits": menu_item['Ingredient_1__r']['Health_Benefits__c'] if 'Ingredient_1__r' in menu_item else 'No health benefits available',
|
181 |
-
"fun_facts": menu_item['Ingredient_1__r']['Fun_Facts__c'] if 'Ingredient_1__r' in menu_item else 'No fun facts available'
|
182 |
-
},
|
183 |
-
{
|
184 |
-
"name": menu_item['Ingredient_2__r']['Ingredient_Name__c'] if 'Ingredient_2__r' in menu_item else None,
|
185 |
-
"image": menu_item['Ingredient_2__r']['Ingredient_Image__c'] if 'Ingredient_2__r' in menu_item else None,
|
186 |
-
"health_benefits": menu_item['Ingredient_2__r']['Health_Benefits__c'] if 'Ingredient_2__r' in menu_item else 'No health benefits available',
|
187 |
-
"fun_facts": menu_item['Ingredient_2__r']['Fun_Facts__c'] if 'Ingredient_2__r' in menu_item else 'No fun facts available'
|
188 |
-
}
|
189 |
-
]
|
190 |
})
|
191 |
-
|
192 |
else:
|
193 |
print(f"Item not found in menu: {item_name_cleaned}")
|
194 |
|
@@ -197,6 +221,7 @@ def order_summary():
|
|
197 |
else:
|
198 |
print(f"Total items extracted: {len(order_items)}")
|
199 |
|
|
|
200 |
return render_template(
|
201 |
'reward_status.html',
|
202 |
order_items=order_items
|
@@ -207,6 +232,7 @@ def order_summary():
|
|
207 |
return f"Error querying Salesforce: {str(e)}", 500
|
208 |
|
209 |
|
|
|
210 |
@app.route("/logout")
|
211 |
def logout():
|
212 |
# Retrieve table number before clearing session
|
|
|
119 |
|
120 |
return render_template("login.html")
|
121 |
|
122 |
+
# Assuming you're fetching the order details and processing them like this
|
123 |
+
|
124 |
@app.route('/order_summary')
|
125 |
def order_summary():
|
126 |
email = session.get('user_email')
|
|
|
158 |
item_name = item_parts[0].strip()
|
159 |
item_name_cleaned = ' '.join(item_name.split(' ')[:-1]).strip()
|
160 |
|
161 |
+
print(f"Processing Item: {item_name_cleaned}")
|
162 |
+
|
163 |
menu_query = f"""
|
164 |
SELECT Name, Price__c, Image1__c, Ingredient_1__r.Ingredient_Name__c,
|
165 |
Ingredient_1__r.Ingredient_Image__c, Ingredient_1__r.Health_Benefits__c,
|
|
|
169 |
FROM Menu_Item__c
|
170 |
WHERE Name = '{item_name_cleaned}'
|
171 |
"""
|
172 |
+
print(f"Executing Query for {item_name_cleaned}: {menu_query}")
|
173 |
+
|
174 |
menu_result = sf.query(menu_query)
|
175 |
+
print(f"Menu Result for {item_name_cleaned}: {menu_result}")
|
176 |
|
177 |
if menu_result.get("records"):
|
178 |
menu_item = menu_result["records"][0]
|
179 |
+
ingredients = []
|
180 |
+
|
181 |
+
# Check and add Ingredient 1
|
182 |
+
if 'Ingredient_1__r' in menu_item:
|
183 |
+
print(f"Ingredient 1 Found for {item_name_cleaned}: {menu_item['Ingredient_1__r']}")
|
184 |
+
ingredients.append({
|
185 |
+
"name": menu_item['Ingredient_1__r']['Ingredient_Name__c'],
|
186 |
+
"image": menu_item['Ingredient_1__r']['Ingredient_Image__c'],
|
187 |
+
"health_benefits": menu_item['Ingredient_1__r']['Health_Benefits__c'] or "No health benefits available",
|
188 |
+
"fun_facts": menu_item['Ingredient_1__r']['Fun_Facts__c'] or "No fun facts available"
|
189 |
+
})
|
190 |
+
else:
|
191 |
+
print(f"Ingredient 1 missing for {item_name_cleaned}")
|
192 |
+
|
193 |
+
# Check and add Ingredient 2
|
194 |
+
if 'Ingredient_2__r' in menu_item:
|
195 |
+
print(f"Ingredient 2 Found for {item_name_cleaned}: {menu_item['Ingredient_2__r']}")
|
196 |
+
ingredients.append({
|
197 |
+
"name": menu_item['Ingredient_2__r']['Ingredient_Name__c'],
|
198 |
+
"image": menu_item['Ingredient_2__r']['Ingredient_Image__c'],
|
199 |
+
"health_benefits": menu_item['Ingredient_2__r']['Health_Benefits__c'] or "No health benefits available",
|
200 |
+
"fun_facts": menu_item['Ingredient_2__r']['Fun_Facts__c'] or "No fun facts available"
|
201 |
+
})
|
202 |
+
else:
|
203 |
+
print(f"Ingredient 2 missing for {item_name_cleaned}")
|
204 |
+
|
205 |
+
# If ingredients are missing, log the missing item
|
206 |
+
if not ingredients:
|
207 |
+
print(f"No ingredients found for {item_name_cleaned}")
|
208 |
+
|
209 |
order_items.append({
|
210 |
"name": item_name_cleaned,
|
211 |
"price": menu_item.get("Price__c"),
|
212 |
"image_url": menu_item.get("Image1__c"),
|
213 |
+
"ingredients": ingredients
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
})
|
215 |
+
|
216 |
else:
|
217 |
print(f"Item not found in menu: {item_name_cleaned}")
|
218 |
|
|
|
221 |
else:
|
222 |
print(f"Total items extracted: {len(order_items)}")
|
223 |
|
224 |
+
# Pass the order_items to the template
|
225 |
return render_template(
|
226 |
'reward_status.html',
|
227 |
order_items=order_items
|
|
|
232 |
return f"Error querying Salesforce: {str(e)}", 500
|
233 |
|
234 |
|
235 |
+
|
236 |
@app.route("/logout")
|
237 |
def logout():
|
238 |
# Retrieve table number before clearing session
|