Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 182 |
-
product_name =
|
| 183 |
-
if product_name:
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
mapped_attributes = {}
|
| 192 |
for key, value in attributes.items():
|
| 193 |
-
|
| 194 |
-
if
|
| 195 |
-
mapped_attributes[
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
| 198 |
|
|
|
|
| 199 |
if not mapped_attributes:
|
| 200 |
-
return "No valid attributes found to export."
|
| 201 |
|
| 202 |
-
|
| 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":
|