gopichandra commited on
Commit
f8e628d
·
verified ·
1 Parent(s): 2284e44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -158,23 +158,21 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
158
  security_token=SALESFORCE_SECURITY_TOKEN
159
  )
160
 
161
- # Determine Salesforce Object and Quantity Field for Entry Mode
162
  object_name = None
163
- product_field_name = "Product_Name__c" # Needs verification
164
- model_field_name = "Modal_Name__c" # Needs verification
165
  quantity_field = None
166
 
167
  if mode == "Entry":
168
  if entry_type == "Sales":
169
  object_name = "VENKATA_RAMANA_MOTORS__c"
170
- quantity_field = "Quantity__c" # Needs verification
171
- product_field_name = "Productname__c" # Adjusted based on ENTRY Mode fields
172
- model_field_name = "Model__c" # Adjusted based on ENTRY Mode fields
173
  elif entry_type == "Non-Sales":
174
  object_name = "UNBILLING_DATA__c"
175
  quantity_field = "TotalQuantity__c"
176
 
177
- elif mode == "Exit": # Exit Mode is working fine, so we don't touch it
178
  if entry_type == "Sales":
179
  object_name = "Inventory_Management__c"
180
  quantity_field = "Quantity_Sold__c"
@@ -193,11 +191,6 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
193
  if not product_name and not model_name:
194
  return "❌ No product name or model name detected. Please provide a valid product or model."
195
 
196
- # Adjust the field names for Entry Mode to match correct fields in Salesforce
197
- if mode == "Entry":
198
- product_field_name = "Productname__c" # Adjusted based on ENTRY Mode
199
- model_field_name = "Model__c" # Adjusted based on ENTRY Mode
200
-
201
  # Build Query to Find Matching Product
202
  query_conditions = []
203
  if product_name:
@@ -214,13 +207,13 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
214
  record_id = response["records"][0]["Id"]
215
  existing_quantity = response["records"][0].get(quantity_field, 0)
216
 
217
- # Update quantity directly
218
- updated_quantity = quantity # Just set the new quantity without adding/subtracting
219
 
220
  sf.__getattr__(object_name).update(record_id, {quantity_field: updated_quantity})
221
  return f"✅ Successfully updated quantity for '{product_name or model_name}' in {object_name}. New {quantity_field}: {updated_quantity}."
222
  else:
223
- return f"❌ No matching product found in {object_name}. Check field names or product/model data."
224
 
225
  except Exception as e:
226
  return f"❌ Error interacting with Salesforce: {str(e)}"
 
158
  security_token=SALESFORCE_SECURITY_TOKEN
159
  )
160
 
161
+ # Determine Salesforce Object and Quantity Field
162
  object_name = None
163
+ product_field_name = "Productname__c" # Ensure correct field name for Entry Mode
164
+ model_field_name = "Model__c" # Ensure correct field name for Entry Mode
165
  quantity_field = None
166
 
167
  if mode == "Entry":
168
  if entry_type == "Sales":
169
  object_name = "VENKATA_RAMANA_MOTORS__c"
170
+ quantity_field = "Quantity__c" # Check the correct field name in Salesforce
 
 
171
  elif entry_type == "Non-Sales":
172
  object_name = "UNBILLING_DATA__c"
173
  quantity_field = "TotalQuantity__c"
174
 
175
+ elif mode == "Exit": # Keep Exit Mode logic unchanged
176
  if entry_type == "Sales":
177
  object_name = "Inventory_Management__c"
178
  quantity_field = "Quantity_Sold__c"
 
191
  if not product_name and not model_name:
192
  return "❌ No product name or model name detected. Please provide a valid product or model."
193
 
 
 
 
 
 
194
  # Build Query to Find Matching Product
195
  query_conditions = []
196
  if product_name:
 
207
  record_id = response["records"][0]["Id"]
208
  existing_quantity = response["records"][0].get(quantity_field, 0)
209
 
210
+ # Update quantity directly without modifying other fields
211
+ updated_quantity = quantity # Directly set the new quantity
212
 
213
  sf.__getattr__(object_name).update(record_id, {quantity_field: updated_quantity})
214
  return f"✅ Successfully updated quantity for '{product_name or model_name}' in {object_name}. New {quantity_field}: {updated_quantity}."
215
  else:
216
+ return f"❌ No matching product found in {object_name}. Please check the product/model name."
217
 
218
  except Exception as e:
219
  return f"❌ Error interacting with Salesforce: {str(e)}"