Update app.py
Browse files
app.py
CHANGED
@@ -253,73 +253,6 @@ def update_profile():
|
|
253 |
|
254 |
|
255 |
|
256 |
-
from datetime import datetime
|
257 |
-
import pytz # Library to handle timezone conversions
|
258 |
-
|
259 |
-
@app.route("/order-history", methods=["GET"])
|
260 |
-
def order_history():
|
261 |
-
email = session.get('user_email') # Get logged-in user's email
|
262 |
-
if not email:
|
263 |
-
return redirect(url_for("login"))
|
264 |
-
|
265 |
-
try:
|
266 |
-
# Fetch past orders for the user
|
267 |
-
result = sf.query(f"""
|
268 |
-
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c,
|
269 |
-
Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c, CreatedDate
|
270 |
-
FROM Order__c
|
271 |
-
WHERE Customer_Email__c = '{email}'
|
272 |
-
ORDER BY CreatedDate DESC
|
273 |
-
""")
|
274 |
-
|
275 |
-
print(f"Salesforce query result: {result}") # Debugging line
|
276 |
-
|
277 |
-
orders = result.get("records", []) # Fetch all orders
|
278 |
-
|
279 |
-
if not orders:
|
280 |
-
print("No orders found for this email.") # Debugging line
|
281 |
-
|
282 |
-
# Format the order details for better readability
|
283 |
-
for order in orders:
|
284 |
-
order_details = order.get("Order_Details__c", "")
|
285 |
-
items = order_details.split("\n") # Assuming each item is separated by a new line
|
286 |
-
formatted_items = []
|
287 |
-
|
288 |
-
# Loop through the items and format them as "item name * quantity"
|
289 |
-
for item in items:
|
290 |
-
item_details = item.split(" | ")
|
291 |
-
if len(item_details) > 1:
|
292 |
-
name = item_details[0].strip()
|
293 |
-
quantity = item_details[1].strip()
|
294 |
-
formatted_items.append(f"{name} * {quantity}")
|
295 |
-
|
296 |
-
# Join the formatted items into a single string
|
297 |
-
order['formatted_items'] = ", ".join(formatted_items)
|
298 |
-
|
299 |
-
# Get the order date and time from CreatedDate
|
300 |
-
created_date = order.get("CreatedDate", "")
|
301 |
-
if created_date:
|
302 |
-
# Convert CreatedDate to datetime object in UTC
|
303 |
-
utc_datetime = datetime.strptime(created_date, '%Y-%m-%dT%H:%M:%S.000+0000')
|
304 |
-
utc_datetime = utc_datetime.replace(tzinfo=pytz.UTC)
|
305 |
-
|
306 |
-
# Convert UTC datetime to the desired timezone (e.g., IST)
|
307 |
-
local_timezone = pytz.timezone('Asia/Kolkata') # Replace with your timezone
|
308 |
-
local_datetime = utc_datetime.astimezone(local_timezone)
|
309 |
-
|
310 |
-
# Format the date and time in the desired format
|
311 |
-
order['formatted_date'] = local_datetime.strftime('%B %d, %I:%M %p')
|
312 |
-
|
313 |
-
order_status = order.get("Order_Status__c", "N/A") # Default to "N/A" if no status
|
314 |
-
order['order_status'] = order_status
|
315 |
-
|
316 |
-
|
317 |
-
return render_template("order_history.html", orders=orders)
|
318 |
-
|
319 |
-
except Exception as e:
|
320 |
-
print(f"Error fetching order history: {str(e)}")
|
321 |
-
return render_template("order_history.html", orders=[], error=str(e))
|
322 |
-
|
323 |
|
324 |
app.permanent_session_lifetime = timedelta(minutes=5)
|
325 |
@app.before_request
|
|
|
253 |
|
254 |
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
app.permanent_session_lifetime = timedelta(minutes=5)
|
258 |
@app.before_request
|