Spaces:
Runtime error
Runtime error
Update order.py
Browse files
order.py
CHANGED
@@ -14,7 +14,7 @@ def order_summary():
|
|
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
|
@@ -22,10 +22,35 @@ def order_summary():
|
|
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))
|
|
|
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, Billing_Status__c
|
18 |
FROM Order__c
|
19 |
WHERE Customer_Email__c = '{email}'
|
20 |
ORDER BY CreatedDate DESC
|
|
|
22 |
""")
|
23 |
order = result.get("records", [])[0] if result.get("records") else None
|
24 |
|
25 |
+
# Fetch the previous order if its Billing_Status__c is 'Pending'
|
26 |
+
pending_result = sf.query(f"""
|
27 |
+
SELECT Id, Total_Bill__c, Discount__c, Total_Amount__c
|
28 |
+
FROM Order__c
|
29 |
+
WHERE Customer_Email__c = '{email}' AND Billing_Status__c = 'Pending'
|
30 |
+
ORDER BY CreatedDate DESC
|
31 |
+
LIMIT 1
|
32 |
+
""")
|
33 |
+
pending_order = pending_result.get("records", [])[0] if pending_result.get("records") else None
|
34 |
+
|
35 |
if not order:
|
36 |
return render_template("order.html", order=None)
|
37 |
|
38 |
+
if pending_order:
|
39 |
+
# Add the pending bill's total to the current order
|
40 |
+
previous_total = pending_order["Total_Bill__c"]
|
41 |
+
order["Total_Amount__c"] += previous_total # Add the pending bill amount
|
42 |
+
order["Discount__c"] += pending_order["Discount__c"] # Add any discounts if applicable
|
43 |
+
order["Total_Bill__c"] += previous_total # Update the total bill
|
44 |
+
|
45 |
+
# Optionally, you can update the order in Salesforce to reflect the new total
|
46 |
+
# sf.Order__c.update(order['Id'], {
|
47 |
+
# 'Total_Amount__c': order['Total_Amount__c'],
|
48 |
+
# 'Discount__c': order['Discount__c'],
|
49 |
+
# 'Total_Bill__c': order['Total_Bill__c']
|
50 |
+
# })
|
51 |
+
|
52 |
return render_template("order.html", order=order)
|
53 |
+
|
54 |
except Exception as e:
|
55 |
print(f"Error fetching order details: {str(e)}")
|
56 |
+
return render_template("order.html", order=None, error=str(e))
|