Update app.py
Browse files
app.py
CHANGED
|
@@ -158,69 +158,7 @@ def generate_custom_dish():
|
|
| 158 |
except Exception as e:
|
| 159 |
return jsonify({"success": False, "error": str(e)}), 500
|
| 160 |
|
| 161 |
-
@app.route("/order-history", methods=["GET"])
|
| 162 |
-
def order_history():
|
| 163 |
-
email = session.get('user_email') # Get logged-in user's email
|
| 164 |
-
if not email:
|
| 165 |
-
return redirect(url_for("login"))
|
| 166 |
|
| 167 |
-
try:
|
| 168 |
-
# Fetch past orders for the user
|
| 169 |
-
result = sf.query(f"""
|
| 170 |
-
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c,
|
| 171 |
-
Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c, CreatedDate
|
| 172 |
-
FROM Order__c
|
| 173 |
-
WHERE Customer_Email__c = '{email}'
|
| 174 |
-
ORDER BY CreatedDate DESC
|
| 175 |
-
""")
|
| 176 |
-
|
| 177 |
-
print(f"Salesforce query result: {result}") # Debugging line
|
| 178 |
-
|
| 179 |
-
orders = result.get("records", []) # Fetch all orders
|
| 180 |
-
|
| 181 |
-
if not orders:
|
| 182 |
-
print("No orders found for this email.") # Debugging line
|
| 183 |
-
|
| 184 |
-
# Format the order details for better readability
|
| 185 |
-
for order in orders:
|
| 186 |
-
order_details = order.get("Order_Details__c", "")
|
| 187 |
-
items = order_details.split("\n") # Assuming each item is separated by a new line
|
| 188 |
-
formatted_items = []
|
| 189 |
-
|
| 190 |
-
# Loop through the items and format them as "item name * quantity"
|
| 191 |
-
for item in items:
|
| 192 |
-
item_details = item.split(" | ")
|
| 193 |
-
if len(item_details) > 1:
|
| 194 |
-
name = item_details[0].strip()
|
| 195 |
-
quantity = item_details[1].strip()
|
| 196 |
-
formatted_items.append(f"{name} * {quantity}")
|
| 197 |
-
|
| 198 |
-
# Join the formatted items into a single string
|
| 199 |
-
order['formatted_items'] = ", ".join(formatted_items)
|
| 200 |
-
|
| 201 |
-
# Get the order date and time from CreatedDate
|
| 202 |
-
created_date = order.get("CreatedDate", "")
|
| 203 |
-
if created_date:
|
| 204 |
-
# Convert CreatedDate to datetime object in UTC
|
| 205 |
-
utc_datetime = datetime.strptime(created_date, '%Y-%m-%dT%H:%M:%S.000+0000')
|
| 206 |
-
utc_datetime = utc_datetime.replace(tzinfo=pytz.UTC)
|
| 207 |
-
|
| 208 |
-
# Convert UTC datetime to the desired timezone (e.g., IST)
|
| 209 |
-
local_timezone = pytz.timezone('Asia/Kolkata') # Replace with your timezone
|
| 210 |
-
local_datetime = utc_datetime.astimezone(local_timezone)
|
| 211 |
-
|
| 212 |
-
# Format the date and time in the desired format
|
| 213 |
-
order['formatted_date'] = local_datetime.strftime('%B %d, %I:%M %p')
|
| 214 |
-
|
| 215 |
-
order_status = order.get("Order_Status__c", "N/A") # Default to "N/A" if no status
|
| 216 |
-
order['order_status'] = order_status
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
return render_template("order_history.html", orders=orders)
|
| 220 |
-
|
| 221 |
-
except Exception as e:
|
| 222 |
-
print(f"Error fetching order history: {str(e)}")
|
| 223 |
-
return render_template("order_history.html", orders=[], error=str(e))
|
| 224 |
|
| 225 |
|
| 226 |
app.permanent_session_lifetime = timedelta(minutes=5)
|
|
|
|
| 158 |
except Exception as e:
|
| 159 |
return jsonify({"success": False, "error": str(e)}), 500
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
app.permanent_session_lifetime = timedelta(minutes=5)
|