Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -254,6 +254,10 @@ def customer_details():
254
  print(f"Error fetching customer details: {str(e)}")
255
  return jsonify({"success": False, "message": f"Error fetching customer details: {str(e)}"})
256
 
 
 
 
 
257
  @app.route("/order-history", methods=["GET"])
258
  def order_history():
259
  email = session.get('user_email') # Get logged-in user's email
@@ -270,25 +274,54 @@ def order_history():
270
  ORDER BY CreatedDate DESC
271
  """)
272
 
 
 
273
  orders = result.get("records", []) # Fetch all orders
274
 
275
- # Strip image URLs from order details and split remaining data by new lines
 
 
 
276
  for order in orders:
277
  order_details = order.get("Order_Details__c", "")
278
- # Remove image URLs using regex
279
- cleaned_details = re.sub(r'http[s]?://\S+', '', order_details)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
- # Now split the cleaned details by lines and join them with <br> to create line breaks
282
- cleaned_details = cleaned_details.replace("\n", " ")
 
283
 
284
- # Update the order details with the cleaned and formatted details
285
- order['Order_Details__c'] = cleaned_details
286
 
287
  return render_template("order_history.html", orders=orders)
288
 
289
  except Exception as e:
290
  print(f"Error fetching order history: {str(e)}")
291
  return render_template("order_history.html", orders=[], error=str(e))
 
 
 
 
 
292
  app.permanent_session_lifetime = timedelta(minutes=5)
293
  @app.before_request
294
  def check_session_timeout():
 
254
  print(f"Error fetching customer details: {str(e)}")
255
  return jsonify({"success": False, "message": f"Error fetching customer details: {str(e)}"})
256
 
257
+
258
+ from datetime import datetime
259
+ import pytz # Library to handle timezone conversions
260
+
261
  @app.route("/order-history", methods=["GET"])
262
  def order_history():
263
  email = session.get('user_email') # Get logged-in user's email
 
274
  ORDER BY CreatedDate DESC
275
  """)
276
 
277
+ print(f"Salesforce query result: {result}") # Debugging line
278
+
279
  orders = result.get("records", []) # Fetch all orders
280
 
281
+ if not orders:
282
+ print("No orders found for this email.") # Debugging line
283
+
284
+ # Format the order details for better readability
285
  for order in orders:
286
  order_details = order.get("Order_Details__c", "")
287
+ items = order_details.split("\n") # Assuming each item is separated by a new line
288
+ formatted_items = []
289
+
290
+ # Loop through the items and format them as "item name * quantity"
291
+ for item in items:
292
+ item_details = item.split(" | ")
293
+ if len(item_details) > 1:
294
+ name = item_details[0].strip()
295
+ quantity = item_details[1].strip()
296
+ formatted_items.append(f"{name} * {quantity}")
297
+
298
+ # Join the formatted items into a single string
299
+ order['formatted_items'] = ", ".join(formatted_items)
300
+
301
+ # Get the order date and time from CreatedDate
302
+ created_date = order.get("CreatedDate", "")
303
+ if created_date:
304
+ # Convert CreatedDate to datetime object in UTC
305
+ utc_datetime = datetime.strptime(created_date, '%Y-%m-%dT%H:%M:%S.000+0000')
306
+ utc_datetime = utc_datetime.replace(tzinfo=pytz.UTC)
307
 
308
+ # Convert UTC datetime to the desired timezone (e.g., IST)
309
+ local_timezone = pytz.timezone('Asia/Kolkata') # Replace with your timezone
310
+ local_datetime = utc_datetime.astimezone(local_timezone)
311
 
312
+ # Format the date and time in the desired format
313
+ order['formatted_date'] = local_datetime.strftime('%B %d, %I:%M %p')
314
 
315
  return render_template("order_history.html", orders=orders)
316
 
317
  except Exception as e:
318
  print(f"Error fetching order history: {str(e)}")
319
  return render_template("order_history.html", orders=[], error=str(e))
320
+
321
+
322
+
323
+
324
+
325
  app.permanent_session_lifetime = timedelta(minutes=5)
326
  @app.before_request
327
  def check_session_timeout():