nagasurendra commited on
Commit
6bbfc57
·
verified ·
1 Parent(s): b83afe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -31
app.py CHANGED
@@ -52,39 +52,32 @@ from flask import render_template
52
  from simple_salesforce import Salesforce
53
  import json
54
 
 
 
 
55
 
56
- @app.route('/previous_orders')
57
- def previous_orders():
58
- email = 'customer_email@example.com' # Get the email dynamically (e.g., from session or request)
59
-
60
- # Query Salesforce to fetch previous orders based on the email
61
- query = f"SELECT Order_Details__c, Total_Amount__c, Order_Date__c FROM Order__c WHERE Customer_Email__c = '{email}'"
62
- orders = sf.query(query)
63
-
64
- # Process each order and extract details
65
- processed_orders = []
66
- for order in orders['records']:
67
- order_details = order['Order_Details__c']
68
- items = order_details.split('\n')
69
- order_items = []
70
-
71
- for item in items:
72
- item_parts = item.split('|')
73
- order_items.append({
74
- 'name': item_parts[0].strip(),
75
- 'addons': item_parts[1].strip().replace('Add-Ons:', ''),
76
- 'instructions': item_parts[2].strip().replace('Instructions:', ''),
77
- 'price': item_parts[3].strip().replace('Price:', ''),
78
- 'image': item_parts[4].strip().replace('Image:', ''),
79
- })
80
 
81
- processed_orders.append({
82
- 'items': order_items,
83
- 'total_amount': order['Total_Amount__c'],
84
- 'order_date': order['Order_Date__c']
85
- })
86
-
87
- return render_template('previous_orders.html', orders=processed_orders)
88
 
89
 
90
  @app.route("/signup", methods=["GET", "POST"])
 
52
  from simple_salesforce import Salesforce
53
  import json
54
 
55
+ @app.route("/order-history")
56
+ def order_history():
57
+ email = session.get('user_email') # Get the logged-in user's email
58
 
59
+ if not email:
60
+ return redirect(url_for("login")) # If not logged in, redirect to login
61
+
62
+ try:
63
+ # Fetch order records for the logged-in user
64
+ result = sf.query(f"""
65
+ SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c,
66
+ Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c, CreatedDate
67
+ FROM Order__c
68
+ WHERE Customer_Email__c = '{email}'
69
+ ORDER BY CreatedDate DESC
70
+ LIMIT 5
71
+ """)
72
+
73
+ orders = result.get("records", []) # Get the order records (max 5)
 
 
 
 
 
 
 
 
 
74
 
75
+ return render_template("order_history.html", orders=orders) # Pass to template
76
+
77
+ except Exception as e:
78
+ print(f"Error fetching order history: {str(e)}")
79
+ return render_template("order_history.html", orders=[], error=str(e))
80
+
 
81
 
82
 
83
  @app.route("/signup", methods=["GET", "POST"])