lokesh341 commited on
Commit
af6c18b
·
verified ·
1 Parent(s): d93ba85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -130,6 +130,39 @@ def get_item_details():
130
  logger.error(f"Failed to fetch item details: {str(e)}")
131
  return jsonify({"error": "Failed to fetch item details from Salesforce"}), 500
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  # Submit selected items to Ingredient_Object__c
134
  @app.route('/submit_items', methods=['POST'])
135
  def submit_items():
@@ -147,7 +180,8 @@ def submit_items():
147
  for item in items:
148
  logger.info(f"Submitting item: {item}")
149
  sf.Ingredient_Object__c.create({
150
- 'Ingredient_Name__c': item['name']
 
151
  })
152
  logger.info(f"Successfully submitted item to Ingredient_Object__c: {item['name']}")
153
  return jsonify({"success": f"Successfully submitted {len(items)} items to Salesforce"})
 
130
  logger.error(f"Failed to fetch item details: {str(e)}")
131
  return jsonify({"error": "Failed to fetch item details from Salesforce"}), 500
132
 
133
+ # Fetch item details from Sector_Detail__c by name
134
+ @app.route('/get_item_details_by_name', methods=['POST'])
135
+ def get_item_details_by_name():
136
+ global sf
137
+ if not sf:
138
+ sf = get_salesforce_connection()
139
+ if not sf:
140
+ return jsonify({"error": "Unable to connect to Salesforce"}), 500
141
+
142
+ item_name = request.json.get('item_name', '').strip()
143
+ if not item_name:
144
+ return jsonify({"error": "Item name is required"}), 400
145
+
146
+ try:
147
+ soql = f"SELECT Name, Category__c, Description__c FROM Sector_Detail__c WHERE Name LIKE '%{item_name}%' LIMIT 1"
148
+ logger.info(f"Executing SOQL query: {soql}")
149
+ result = sf.query(soql)
150
+
151
+ if result['totalSize'] == 0:
152
+ return jsonify({"error": f"No item found matching '{item_name}' in Sector_Detail__c"}), 404
153
+
154
+ record = result['records'][0]
155
+ item_details = {
156
+ "name": record.get('Name', ''),
157
+ "category": record.get('Category__c', 'Unknown'),
158
+ "description": record.get('Description__c', 'No description available')
159
+ }
160
+ logger.info(f"Fetched details for '{item_name}' from Sector_Detail__c")
161
+ return jsonify({"item_details": item_details})
162
+ except Exception as e:
163
+ logger.error(f"Failed to fetch item details from Sector_Detail__c: {str(e)}")
164
+ return jsonify({"error": f"Failed to fetch item details from Salesforce: {str(e)}"}), 500
165
+
166
  # Submit selected items to Ingredient_Object__c
167
  @app.route('/submit_items', methods=['POST'])
168
  def submit_items():
 
180
  for item in items:
181
  logger.info(f"Submitting item: {item}")
182
  sf.Ingredient_Object__c.create({
183
+ 'Ingredient_Name__c': item['name'],
184
+ 'Description__c': item.get('description', 'No description available')
185
  })
186
  logger.info(f"Successfully submitted item to Ingredient_Object__c: {item['name']}")
187
  return jsonify({"success": f"Successfully submitted {len(items)} items to Salesforce"})