Rammohan0504 commited on
Commit
5fba391
·
verified ·
1 Parent(s): 213ed7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -537,15 +537,15 @@ def apply_coupon():
537
  except Exception as e:
538
  return jsonify({'success': False, 'message': f'Error applying coupon: {str(e)}'})
539
 
540
-
541
  @app.route("/order", methods=["GET"])
542
  def order_summary():
543
- email = session.get('user_email') # Fetch logged-in user's email
 
544
  if not email:
545
  return redirect(url_for("login"))
546
 
547
  try:
548
- # Fetch the most recent order for the user
549
  result = sf.query(f"""
550
  SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c
551
  FROM Order__c
@@ -556,12 +556,23 @@ def order_summary():
556
  order = result.get("records", [])[0] if result.get("records") else None
557
 
558
  if not order:
559
- return render_template("order.html", order=None)
 
 
 
 
 
 
 
 
 
 
560
 
561
- return render_template("order.html", order=order)
562
  except Exception as e:
563
  print(f"Error fetching order details: {str(e)}")
564
- return render_template("order.html", order=None, error=str(e))
 
 
565
 
566
  if __name__ == "__main__":
567
  app.run(debug=False, host="0.0.0.0", port=7860)
 
537
  except Exception as e:
538
  return jsonify({'success': False, 'message': f'Error applying coupon: {str(e)}'})
539
 
 
540
  @app.route("/order", methods=["GET"])
541
  def order_summary():
542
+ email = session.get('user_email')
543
+
544
  if not email:
545
  return redirect(url_for("login"))
546
 
547
  try:
548
+ # Fetch order details
549
  result = sf.query(f"""
550
  SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c
551
  FROM Order__c
 
556
  order = result.get("records", [])[0] if result.get("records") else None
557
 
558
  if not order:
559
+ return render_template("order_summary.html", order=None)
560
+
561
+ # Calculate final total after discount
562
+ final_total = order['Total_Amount__c']
563
+ if 'Coupon_Code__c' in order and order['Coupon_Code__c']:
564
+ coupon_code = order['Coupon_Code__c']
565
+ # Apply a discount, for example 10% for now
566
+ discount = 0.1 # 10% discount
567
+ final_total = order['Total_Amount__c'] - (order['Total_Amount__c'] * discount)
568
+
569
+ return render_template("order_summary.html", order=order, final_total=final_total)
570
 
 
571
  except Exception as e:
572
  print(f"Error fetching order details: {str(e)}")
573
+ return render_template("order_summary.html", error=str(e))
574
+
575
+
576
 
577
  if __name__ == "__main__":
578
  app.run(debug=False, host="0.0.0.0", port=7860)