gopichandra commited on
Commit
7b8ca14
·
verified ·
1 Parent(s): 98dbcff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -135,7 +135,6 @@ def interact_with_salesforce(mode, entry_type, quantity, attributes):
135
  security_token=SALESFORCE_SECURITY_TOKEN
136
  )
137
 
138
- # Mapping mode and entry_type to Salesforce object and field
139
  object_name = None
140
  field_name = None
141
  field_names = []
@@ -162,23 +161,19 @@ def interact_with_salesforce(mode, entry_type, quantity, attributes):
162
  if not object_name or (not field_name and not field_names):
163
  return "Invalid mode or entry type."
164
 
165
- # Get valid fields for the specified Salesforce object
166
  sf_object = sf.__getattr__(object_name)
167
  schema = sf_object.describe()
168
  valid_fields = {field["name"] for field in schema["fields"]}
169
 
170
- # Filter attributes for valid Salesforce fields
171
  filtered_attributes = filter_valid_attributes(attributes, valid_fields)
172
 
173
- # Handling "Exit" Mode (Updating Records)
174
  if mode == "Exit":
175
- # Query should match exact product name, model name, stage, and hp if available
176
  query_conditions = [f"{product_field_name} = '{attributes['Product name']}'"]
177
- if "Model Name" in attributes:
178
  query_conditions.append(f"{model_field_name} = '{attributes['Model Name']}'")
179
- if "Stage" in attributes:
180
  query_conditions.append(f"{stage_field_name} = '{attributes['Stage']}'")
181
- if "H.P." in attributes:
182
  query_conditions.append(f"{hp_field_name} = '{attributes['H.P.']}'")
183
 
184
  query = f"SELECT Id, {', '.join(field_names)} FROM {object_name} WHERE {' AND '.join(query_conditions)} LIMIT 1"
@@ -192,7 +187,6 @@ def interact_with_salesforce(mode, entry_type, quantity, attributes):
192
  else:
193
  return f"❌ No matching record found for product '{attributes['Product name']}' in {object_name}."
194
 
195
- # Handling "Entry" Mode (Creating Records)
196
  else:
197
  filtered_attributes[field_name] = quantity
198
  sf_object.create(filtered_attributes)
 
135
  security_token=SALESFORCE_SECURITY_TOKEN
136
  )
137
 
 
138
  object_name = None
139
  field_name = None
140
  field_names = []
 
161
  if not object_name or (not field_name and not field_names):
162
  return "Invalid mode or entry type."
163
 
 
164
  sf_object = sf.__getattr__(object_name)
165
  schema = sf_object.describe()
166
  valid_fields = {field["name"] for field in schema["fields"]}
167
 
 
168
  filtered_attributes = filter_valid_attributes(attributes, valid_fields)
169
 
 
170
  if mode == "Exit":
 
171
  query_conditions = [f"{product_field_name} = '{attributes['Product name']}'"]
172
+ if "Model Name" in attributes and attributes["Model Name"]:
173
  query_conditions.append(f"{model_field_name} = '{attributes['Model Name']}'")
174
+ if "Stage" in attributes and attributes["Stage"]:
175
  query_conditions.append(f"{stage_field_name} = '{attributes['Stage']}'")
176
+ if "H.P." in attributes and attributes["H.P."]:
177
  query_conditions.append(f"{hp_field_name} = '{attributes['H.P.']}'")
178
 
179
  query = f"SELECT Id, {', '.join(field_names)} FROM {object_name} WHERE {' AND '.join(query_conditions)} LIMIT 1"
 
187
  else:
188
  return f"❌ No matching record found for product '{attributes['Product name']}' in {object_name}."
189
 
 
190
  else:
191
  filtered_attributes[field_name] = quantity
192
  sf_object.create(filtered_attributes)