nagasurendra commited on
Commit
42e5ba8
·
verified ·
1 Parent(s): 4f13e4d

Update order.py

Browse files
Files changed (1) hide show
  1. order.py +18 -9
order.py CHANGED
@@ -5,6 +5,8 @@ order_blueprint = Blueprint('order', __name__)
5
 
6
  # Initialize Salesforce connection
7
  sf = get_salesforce_connection()
 
 
8
  @order_blueprint.route("/order", methods=["GET"])
9
  def order_summary():
10
  email = session.get('user_email') # Fetch logged-in user's email
@@ -12,20 +14,27 @@ def order_summary():
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))
 
 
5
 
6
  # Initialize Salesforce connection
7
  sf = get_salesforce_connection()
8
+
9
+
10
  @order_blueprint.route("/order", methods=["GET"])
11
  def order_summary():
12
  email = session.get('user_email') # Fetch logged-in user's email
 
14
  return redirect(url_for("login"))
15
 
16
  try:
17
+ # Fetch all pending orders for the user
18
  result = sf.query(f"""
19
+ SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c,
20
+ Order_Status__c, Discount__c, Total_Bill__c
21
  FROM Order__c
22
+ WHERE Customer_Email__c = '{email}' AND Billing_Status__c = 'pending'
23
  ORDER BY CreatedDate DESC
 
24
  """)
25
+ orders = result.get("records", [])
26
+
27
+ if not orders:
28
+ return render_template("order.html", orders=None, total_subtotal=0, total_discount=0, total_bill=0)
29
 
30
+ # Calculate aggregate totals
31
+ total_subtotal = sum(float(order['Total_Amount__c']) for order in orders)
32
+ total_discount = sum(float(order['Discount__c']) for order in orders)
33
+ total_bill = sum(float(order['Total_Bill__c']) for order in orders)
34
 
35
+ return render_template("order.html", orders=orders, total_subtotal=total_subtotal,
36
+ total_discount=total_discount, total_bill=total_bill)
37
  except Exception as e:
38
  print(f"Error fetching order details: {str(e)}")
39
+ return render_template("order.html", orders=None, total_subtotal=0, total_discount=0,
40
+ total_bill=0, error=str(e))