gopichandra commited on
Commit
ca9b01d
·
verified ·
1 Parent(s): 959d465

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -178,30 +178,38 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
178
  # Extract attributes from the extracted text
179
  attributes = extract_attributes(extracted_text)
180
 
181
- # Explicitly extract Product Name from the attributes
182
- product_name = attributes.get("Productname", "").strip() # Extract 'Productname' from the text
183
- if product_name:
184
- # Ensure that the Product Name is mapped to the right Salesforce field
185
- if entry_type == "Sales":
186
- attributes["Product_Name__c"] = product_name # For VENKATA_RAMANA_MOTORS__c
187
- elif entry_type == "Non-Sales":
188
- attributes["Productname__c"] = product_name # For UNBILLING_DATA__c
189
-
190
- # Convert extracted keys to match Salesforce API field names
 
 
191
  mapped_attributes = {}
192
  for key, value in attributes.items():
193
- field_name_sf = key.replace(" ", "_") + "__c" # Convert to Salesforce format
194
- if field_name_sf in valid_fields:
195
- mapped_attributes[field_name_sf] = value # Only keep valid fields
196
 
197
- mapped_attributes[field_name] = quantity # Ensure Quantity is added
 
 
198
 
 
199
  if not mapped_attributes:
200
- return "No valid attributes found to export."
201
 
202
- # Creating a new record with all valid attributes
203
  sf_object.create(mapped_attributes)
204
- return f"✅ Record created in {object_name} with extracted valid attributes and Quantity: {quantity}."
 
 
 
205
 
206
  elif mode == "Exit":
207
  if entry_type == "Sales":
 
178
  # Extract attributes from the extracted text
179
  attributes = extract_attributes(extracted_text)
180
 
181
+ # Ensure Product Name is extracted and mapped correctly
182
+ product_name = match_product_name(extracted_text) # Match product name using fuzzy logic
183
+ if not product_name:
184
+ return "❌ Product Name could not be extracted from the image. Please check the image."
185
+
186
+ # Assign Product Name to the correct Salesforce field
187
+ if entry_type == "Sales":
188
+ attributes["Product_Name__c"] = product_name # For VENKATA_RAMANA_MOTORS__c
189
+ elif entry_type == "Non-Sales":
190
+ attributes["Productname__c"] = product_name # For UNBILLING_DATA__c
191
+
192
+ # Convert extracted keys to match Salesforce API field names
193
  mapped_attributes = {}
194
  for key, value in attributes.items():
195
+ sf_field_name = ATTRIBUTE_MAPPING.get(key, key.replace(" ", "_") + "__c") # Convert to Salesforce format
196
+ if sf_field_name in valid_fields:
197
+ mapped_attributes[sf_field_name] = value # Only keep valid fields
198
 
199
+ # Ensure Product Name and Quantity are added to mapped attributes
200
+ mapped_attributes["Product_Name__c"] = product_name # Product Name field
201
+ mapped_attributes[field_name] = quantity # Quantity field
202
 
203
+ # Ensure at least one valid field exists
204
  if not mapped_attributes:
205
+ return "No valid attributes found to export."
206
 
207
+ # Creating a new record with all valid attributes
208
  sf_object.create(mapped_attributes)
209
+ return f"✅ Record created in {object_name} with extracted valid attributes, Product Name: {product_name}, and Quantity: {quantity}."
210
+
211
+ except Exception as e:
212
+ return f"❌ Error interacting with Salesforce: {str(e)}"
213
 
214
  elif mode == "Exit":
215
  if entry_type == "Sales":