Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -163,6 +163,38 @@ def get_item_details_by_name():
|
|
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():
|
|
|
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 |
+
# Fetch item details (Name and Image_URL) from Sector_Detail__c by name
|
167 |
+
@app.route('/get_sector_item_details', methods=['POST'])
|
168 |
+
def get_sector_item_details():
|
169 |
+
global sf
|
170 |
+
if not sf:
|
171 |
+
sf = get_salesforce_connection()
|
172 |
+
if not sf:
|
173 |
+
return jsonify({"error": "Unable to connect to Salesforce"}), 500
|
174 |
+
|
175 |
+
item_name = request.json.get('item_name', '').strip()
|
176 |
+
if not item_name:
|
177 |
+
return jsonify({"error": "Item name is required"}), 400
|
178 |
+
|
179 |
+
try:
|
180 |
+
soql = f"SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Name LIKE '%{item_name}%' LIMIT 1"
|
181 |
+
logger.info(f"Executing SOQL query: {soql}")
|
182 |
+
result = sf.query(soql)
|
183 |
+
|
184 |
+
if result['totalSize'] == 0:
|
185 |
+
return jsonify({"error": f"No item found matching '{item_name}' in Sector_Detail__c"}), 404
|
186 |
+
|
187 |
+
record = result['records'][0]
|
188 |
+
item_details = {
|
189 |
+
"name": record.get('Name', ''),
|
190 |
+
"image_url": record.get('Image_URL__c', 'https://via.placeholder.com/30')
|
191 |
+
}
|
192 |
+
logger.info(f"Fetched details for '{item_name}' from Sector_Detail__c")
|
193 |
+
return jsonify({"item_details": item_details})
|
194 |
+
except Exception as e:
|
195 |
+
logger.error(f"Failed to fetch item details from Sector_Detail__c: {str(e)}")
|
196 |
+
return jsonify({"error": f"Failed to fetch item details from Salesforce: {str(e)}"}), 500
|
197 |
+
|
198 |
# Submit selected items to Ingredient_Object__c
|
199 |
@app.route('/submit_items', methods=['POST'])
|
200 |
def submit_items():
|