Update order.py
Browse files
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,48 +14,27 @@ def order_summary():
|
|
12 |
return redirect(url_for("login"))
|
13 |
|
14 |
try:
|
15 |
-
# Fetch
|
16 |
result = sf.query(f"""
|
17 |
-
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c,
|
|
|
18 |
FROM Order__c
|
19 |
-
WHERE Customer_Email__c = '{email}'
|
20 |
ORDER BY CreatedDate DESC
|
21 |
-
LIMIT 2
|
22 |
""")
|
23 |
-
|
24 |
orders = result.get("records", [])
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
# Update the previous order's Billing Status to "Completed" after combining the details
|
37 |
-
sf.update('Order__c', previous_order['Id'], {
|
38 |
-
'Billing_Status__c': 'Completed',
|
39 |
-
})
|
40 |
-
|
41 |
-
# Prepare the combined order object
|
42 |
-
order = {
|
43 |
-
'Order_Details__c': combined_order_details,
|
44 |
-
'Total_Amount__c': current_order['Total_Amount__c'],
|
45 |
-
'Discount__c': combined_discount,
|
46 |
-
'Total_Bill__c': combined_total_bill,
|
47 |
-
'Order_Status__c': current_order['Order_Status__c'],
|
48 |
-
'Billing_Status__c': 'Completed', # Mark as completed
|
49 |
-
}
|
50 |
-
|
51 |
-
else:
|
52 |
-
# No previous order with pending billing status
|
53 |
-
order = current_order
|
54 |
-
|
55 |
-
return render_template("order.html", order=order)
|
56 |
-
|
57 |
except Exception as e:
|
58 |
print(f"Error fetching order details: {str(e)}")
|
59 |
-
return render_template("order.html",
|
|
|
|
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))
|