nagasurendra commited on
Commit
53027ce
·
verified ·
1 Parent(s): b60c81b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -64,8 +64,6 @@ def generate_coupon_code(length=10):
64
  characters = string.ascii_uppercase + string.digits # A-Z, 0-9
65
  return ''.join(random.choice(characters) for _ in range(length))
66
 
67
- # Define custom_dishes as a global variable
68
- custom_dishes = []
69
 
70
  @app.route("/generate_custom_dish", methods=["POST"])
71
  def generate_custom_dish():
@@ -88,19 +86,23 @@ def generate_custom_dish():
88
  "Non-Veg" if any(word in description.lower() for word in non_veg_keywords) else \
89
  "Both"
90
 
91
- # Store in the custom dishes list
92
  custom_dish = {
93
- "Name": dish_name,
94
- "Price__c": price,
95
- "Description__c": description,
96
- "Veg_NonVeg__c": category,
97
- "Section__c": "Custom Dishes",
98
- "Total_Ordered__c": 0
99
  }
100
 
101
- custom_dishes.append(custom_dish) # Store in the list
 
102
 
103
- return redirect(url_for("menu", category="Customized Dish")) # Redirect back to the menu with custom dish
 
 
 
104
 
105
  except Exception as e:
106
  return jsonify({"success": False, "error": str(e)}), 500
 
64
  characters = string.ascii_uppercase + string.digits # A-Z, 0-9
65
  return ''.join(random.choice(characters) for _ in range(length))
66
 
 
 
67
 
68
  @app.route("/generate_custom_dish", methods=["POST"])
69
  def generate_custom_dish():
 
86
  "Non-Veg" if any(word in description.lower() for word in non_veg_keywords) else \
87
  "Both"
88
 
89
+ # Create a new Custom_Dish__c record in Salesforce
90
  custom_dish = {
91
+ 'Name': dish_name,
92
+ 'Price__c': price,
93
+ 'Description__c': description,
94
+ 'Veg_NonVeg__c': category,
95
+ 'Section__c': 'Custom Dishes',
96
+ 'Total_Ordered__c': 0
97
  }
98
 
99
+ # Insert the custom dish into Salesforce
100
+ result = sf.Custom_Dish__c.create(custom_dish)
101
 
102
+ if result.get('success'):
103
+ return redirect(url_for("menu", category="Customized Dish")) # Redirect to the menu with custom dish
104
+ else:
105
+ return jsonify({"success": False, "error": "Failed to create custom dish in Salesforce"}), 500
106
 
107
  except Exception as e:
108
  return jsonify({"success": False, "error": str(e)}), 500