File size: 3,102 Bytes
46f20e2 60c7f69 97e16dc 60c7f69 7caf8fd 60c7f69 62801cd 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 e7228d7 6d168f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
from flask import Blueprint, render_template, request, session, jsonify # Added jsonify import
from salesforce import get_salesforce_connection
order_blueprint = Blueprint('order', __name__)
# Initialize Salesforce connection
sf = get_salesforce_connection()
@order_blueprint.route("/order", methods=["GET"])
def order_summary():
email = session.get('user_email') # Fetch logged-in user's email
if not email:
return redirect(url_for("login"))
try:
# Fetch the most recent order for the user
result = sf.query(f"""
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
FROM Order__c
WHERE Customer_Email__c = '{email}'
ORDER BY CreatedDate DESC
LIMIT 1
""")
order = result.get("records", [])[0] if result.get("records") else None
if not order:
return render_template("order.html", order=None)
return render_template("order.html", order=order)
except Exception as e:
print(f"Error fetching order details: {str(e)}")
return render_template("order.html", order=None, error=str(e))
@order_blueprint.route("/order/items", methods=["GET"])
def order_items():
email = session.get('user_email') # Fetch logged-in user's email
if not email:
print("No user email found. Redirecting to login.")
return redirect(url_for("login"))
try:
# Fetch the most recent order for the user
print(f"Fetching order details for email: {email}")
result = sf.query(f"""
SELECT Id, Order_Details__c
FROM Order__c
WHERE Customer_Email__c = '{email}'
ORDER BY CreatedDate DESC
LIMIT 1
""")
# Check if the query was successful and print the result
print("Query result:", result)
order = result.get("records", [])[0] if result.get("records") else None
if not order:
print("No order found for the user.")
return render_template("order_items.html", items=None)
# Extract item names from the order details
item_names = []
if order.get("Order_Details__c"):
print("Found order details. Extracting item names.")
for line in order["Order_Details__c"].split('\n'):
item_parts = line.split('|')
if item_parts:
item_name = item_parts[0].strip() # Assuming the item name is the first part
item_names.append(item_name)
print(f"Extracted item: {item_name}") # Print each extracted item name
if item_names:
print(f"Total items extracted: {len(item_names)}")
else:
print("No items found in order details.")
return render_template("order_items.html", items=item_names)
except Exception as e:
print(f"Error fetching order details: {str(e)}")
return render_template("order_items.html", items=None, error=str(e))
|