Spaces:
Sleeping
Sleeping
Create order.py
Browse files
order.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Blueprint, render_template, request
|
2 |
+
from salesforce import get_salesforce_connection
|
3 |
+
|
4 |
+
order_blueprint = Blueprint('order', __name__)
|
5 |
+
|
6 |
+
# Initialize Salesforce connection
|
7 |
+
sf = get_salesforce_connection()
|
8 |
+
@app.route("/order", methods=["GET"])
|
9 |
+
def order_summary():
|
10 |
+
email = session.get('user_email') # Fetch logged-in user's email
|
11 |
+
if not email:
|
12 |
+
return redirect(url_for("login"))
|
13 |
+
|
14 |
+
try:
|
15 |
+
# Fetch the most recent order for the user
|
16 |
+
result = sf.query(f"""
|
17 |
+
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
|
18 |
+
FROM Order__c
|
19 |
+
WHERE Customer_Email__c = '{email}'
|
20 |
+
ORDER BY CreatedDate DESC
|
21 |
+
LIMIT 1
|
22 |
+
""")
|
23 |
+
order = result.get("records", [])[0] if result.get("records") else None
|
24 |
+
|
25 |
+
if not order:
|
26 |
+
return render_template("order.html", order=None)
|
27 |
+
|
28 |
+
return render_template("order.html", order=order)
|
29 |
+
except Exception as e:
|
30 |
+
print(f"Error fetching order details: {str(e)}")
|
31 |
+
return render_template("order.html", order=None, error=str(e))
|