nagasurendra commited on
Commit
b531c61
·
verified ·
1 Parent(s): 127463e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -73
app.py CHANGED
@@ -78,56 +78,30 @@ def generate_custom_dish():
78
  if not dish_name or not description:
79
  return jsonify({"success": False, "error": "Both fields are required"}), 400
80
 
81
- # Check if the custom dish already exists (case-sensitive check)
82
- query = f"SELECT Id, Name FROM Custom_Dish__c WHERE Name = '{dish_name}'"
83
- result = sf.query(query)
84
-
85
- # If the dish exists, use the existing record ID, otherwise create a new one
86
- if result['records']:
87
- # Custom dish already exists
88
- custom_dish_id = result['records'][0]['Id']
89
- custom_dish = result['records'][0] # Get the existing custom dish record
90
-
91
- # No need to create a new dish, just add it to the cart
92
- # Set up cart item using the existing custom dish details
93
- price = custom_dish['Price__c'] # Use the existing price
94
- email = session.get('user_email') # Assuming you have the user's email in session
95
-
96
- # Create the cart item with custom dish details
97
- cart_item = {
98
- 'Name': dish_name,
99
- 'Price__c': price,
100
- 'Base_Price__c': price,
101
- 'Image1__c': item_image_url,
102
- 'Quantity__c': 1, # Assuming a default quantity of 1 for the custom dish
103
- 'Add_Ons__c': '', # Set Add_ons__c to empty
104
- 'Add_Ons_Price__c': 0, # Set Add_Ons_Price__c to 0
105
- 'Instructions__c': description, # Use the custom dish description as the instructions
106
- 'Customer_Email__c': email, # Associate the custom dish with the logged-in user
107
- 'Custom_Dish__c': custom_dish_id # Link the cart item to the existing custom dish
108
- }
109
-
110
- # Insert the cart item as a Cart_Item__c record in Salesforce
111
- cart_result = sf.Cart_Item__c.create(cart_item)
112
-
113
- if cart_result.get('success'):
114
- return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
115
- else:
116
- return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  else:
119
- # Custom dish does not exist, create a new one
120
- price = random.randint(10, 30) # Example logic for price setting
121
-
122
- # Determine Veg/Non-Veg
123
- veg_keywords = ["paneer", "vegetable", "mushroom", "cheese"]
124
- non_veg_keywords = ["chicken", "mutton", "fish", "egg"]
125
-
126
- category = "Veg" if any(word in description.lower() for word in veg_keywords) else \
127
- "Non veg" if any(word in description.lower() for word in non_veg_keywords) else \
128
- "both"
129
-
130
- # Create a new Custom_Dish__c record in Salesforce
131
  custom_dish = {
132
  'Name': dish_name,
133
  'Price__c': price,
@@ -141,39 +115,39 @@ def generate_custom_dish():
141
  # Insert the custom dish into Salesforce
142
  result = sf.Custom_Dish__c.create(custom_dish)
143
 
144
- if result.get('success'):
145
- # After creating the custom dish, add it to the Cart_Item__c
146
- email = session.get('user_email') # Assuming you have the user's email in session
147
-
148
- # Create the cart item with custom dish details and set other fields to default values
149
- cart_item = {
150
- 'Name': dish_name,
151
- 'Price__c': price,
152
- 'Base_Price__c': price,
153
- 'Image1__c': item_image_url,
154
- 'Quantity__c': 1, # Assuming a default quantity of 1 for the custom dish
155
- 'Add_Ons__c': '', # Set Add_ons__c to empty
156
- 'Add_Ons_Price__c': 0, # Set Add_Ons_Price__c to 0
157
- 'Customer_Email__c': email # Associate the custom dish with the logged-in user
158
- }
159
-
160
- # Insert the custom dish as a Cart_Item__c record in Salesforce
161
- cart_result = sf.Cart_Item__c.create(cart_item)
162
-
163
- if cart_result.get('success'):
164
- return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
165
- else:
166
- return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
167
-
168
- else:
169
  return jsonify({"success": False, "error": "Failed to create custom dish in Salesforce"}), 500
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  except Exception as e:
172
  return jsonify({"success": False, "error": str(e)}), 500
173
 
174
 
175
 
176
 
 
177
  import re
178
  @app.route("/edit_profile", methods=["GET", "POST"])
179
  def edit_profile():
 
78
  if not dish_name or not description:
79
  return jsonify({"success": False, "error": "Both fields are required"}), 400
80
 
81
+ # Generate a random price for the custom dish
82
+ price = random.randint(10, 30) # Example logic for price setting
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ # Determine Veg/Non-Veg
85
+ veg_keywords = ["paneer", "vegetable", "mushroom", "cheese"]
86
+ non_veg_keywords = ["chicken", "mutton", "fish", "egg"]
87
+
88
+ category = "Veg" if any(word in description.lower() for word in veg_keywords) else \
89
+ "Non veg" if any(word in description.lower() for word in non_veg_keywords) else \
90
+ "both"
91
+
92
+ # Query to check if the dish already exists in Salesforce
93
+ existing_dish_query = f"SELECT Id, Name, Price__c, Image1__c, Image2__c, Description__c, Veg_NonVeg__c FROM Custom_Dish__c WHERE Name = '{dish_name}'"
94
+ existing_dish_result = sf.query(existing_dish_query)
95
+
96
+ if existing_dish_result['totalSize'] > 0:
97
+ # If the dish exists, use the existing details
98
+ existing_dish = existing_dish_result['records'][0]
99
+ price = existing_dish['Price__c']
100
+ item_image_url = existing_dish['Image1__c']
101
+ item_image_url2 = existing_dish['Image2__c']
102
+ category = existing_dish['Veg_NonVeg__c']
103
  else:
104
+ # If the dish does not exist, create a new custom dish
 
 
 
 
 
 
 
 
 
 
 
105
  custom_dish = {
106
  'Name': dish_name,
107
  'Price__c': price,
 
115
  # Insert the custom dish into Salesforce
116
  result = sf.Custom_Dish__c.create(custom_dish)
117
 
118
+ if not result.get('success'):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  return jsonify({"success": False, "error": "Failed to create custom dish in Salesforce"}), 500
120
 
121
+ # After ensuring the dish exists, add it to the Cart_Item__c
122
+ email = session.get('user_email') # Assuming you have the user's email in session
123
+
124
+ # Create the cart item with custom dish details and set other fields to default values
125
+ cart_item = {
126
+ 'Name': dish_name,
127
+ 'Price__c': price,
128
+ 'Base_Price__c': price,
129
+ 'Image1__c': item_image_url,
130
+ 'Quantity__c': 1, # Assuming a default quantity of 1 for the custom dish
131
+ 'Add_Ons__c': '', # Set Add_ons__c to empty
132
+ 'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
133
+ 'Customer_Email__c': email # Associate the custom dish with the logged-in user
134
+ }
135
+
136
+ # Insert the custom dish as a Cart_Item__c record in Salesforce
137
+ cart_result = sf.Cart_Item__c.create(cart_item)
138
+
139
+ if cart_result.get('success'):
140
+ return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
141
+ else:
142
+ return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
143
+
144
  except Exception as e:
145
  return jsonify({"success": False, "error": str(e)}), 500
146
 
147
 
148
 
149
 
150
+
151
  import re
152
  @app.route("/edit_profile", methods=["GET", "POST"])
153
  def edit_profile():