nagasurendra commited on
Commit
13d0646
·
verified ·
1 Parent(s): ccf4a29

Update order.py

Browse files
Files changed (1) hide show
  1. order.py +33 -16
order.py CHANGED
@@ -18,24 +18,41 @@ def order_summary():
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
- # Fetch the previous order if its Billing_Status__c is 'Pending'
26
- pending_result = sf.query(f"""
27
- SELECT Id, Order_Details__c, Total_Bill__c, Discount__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, pending_order=None)
37
-
38
- return render_template("order.html", order=order, pending_order=pending_order)
39
 
40
  except Exception as e:
41
  print(f"Error fetching order details: {str(e)}")
 
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
+ current_order = orders[0] if orders else None
26
+ previous_order = orders[1] if len(orders) > 1 else None
27
+
28
+ # Check if previous order exists and if Billing_Status is Pending
29
+ if previous_order and previous_order.get('Billing_Status__c') == 'Pending':
30
+ # Combine details from previous order with the current order
31
+ combined_order_details = f"{previous_order['Order_Details__c']}\n{current_order['Order_Details__c']}"
32
+ combined_total = previous_order['Total_Bill__c'] + current_order['Total_Bill__c']
33
+ combined_discount = previous_order['Discount__c'] + current_order['Discount__c']
34
+ combined_total_bill = combined_total - combined_discount
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)}")