Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -177,20 +177,22 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
|
|
| 177 |
|
| 178 |
# Extract attributes from the extracted text
|
| 179 |
attributes = extract_attributes(extracted_text)
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
|
| 185 |
-
filtered_attributes = {k: v for k, v in attributes.items() if k in valid_fields}
|
| 186 |
-
filtered_attributes[field_name] = quantity # Ensure Quantity is added
|
| 187 |
|
| 188 |
-
if not
|
| 189 |
return "No valid attributes found to export."
|
| 190 |
|
| 191 |
-
|
| 192 |
-
sf_object.create(
|
| 193 |
return f"✅ Record created in {object_name} with extracted valid attributes and Quantity: {quantity}."
|
|
|
|
| 194 |
elif mode == "Exit":
|
| 195 |
if entry_type == "Sales":
|
| 196 |
object_name = "Inventory_Management__c"
|
|
|
|
| 177 |
|
| 178 |
# Extract attributes from the extracted text
|
| 179 |
attributes = extract_attributes(extracted_text)
|
| 180 |
+
# Convert extracted keys to match Salesforce API field names
|
| 181 |
+
mapped_attributes = {}
|
| 182 |
+
for key, value in attributes.items():
|
| 183 |
+
field_name_sf = key.replace(" ", "_") + "__c" # Convert to Salesforce format
|
| 184 |
+
if field_name_sf in valid_fields:
|
| 185 |
+
mapped_attributes[field_name_sf] = value # Only keep valid fields
|
| 186 |
|
| 187 |
+
mapped_attributes[field_name] = quantity # Ensure Quantity is added
|
|
|
|
|
|
|
| 188 |
|
| 189 |
+
if not mapped_attributes:
|
| 190 |
return "No valid attributes found to export."
|
| 191 |
|
| 192 |
+
# Creating a new record with only valid attributes
|
| 193 |
+
sf_object.create(mapped_attributes)
|
| 194 |
return f"✅ Record created in {object_name} with extracted valid attributes and Quantity: {quantity}."
|
| 195 |
+
|
| 196 |
elif mode == "Exit":
|
| 197 |
if entry_type == "Sales":
|
| 198 |
object_name = "Inventory_Management__c"
|