Ajay98 commited on
Commit
9d23069
·
verified ·
1 Parent(s): c77b6a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import os
3
  from paddleocr import PaddleOCR
4
  from PIL import Image
@@ -165,6 +164,7 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
165
  field_names = []
166
  product_field_name = "Product_Name__c"
167
  model_field_name = "Model_Name__c" # Correct field for model name
 
168
  if mode == "Entry":
169
  if entry_type == "Sales":
170
  object_name = "VENKATA_RAMANA_MOTORS__c"
@@ -172,18 +172,18 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
172
  elif entry_type == "Non-Sales":
173
  object_name = "UNBILLING_DATA__c"
174
  field_name = "TotalQuantity__c"
175
- elif mode == "Exit":
176
- if entry_type == "Sales":
177
- object_name = "Inventory_Management__c"
178
- field_names = ["Quantity_Sold__c", "leftstock__c"]
179
- elif entry_type == "Non-Sales":
180
- object_name = "Un_Billable__c"
181
- field_name = "Sold_Out__c"
182
- if not object_name or (not field_name and not field_names):
183
- return "Invalid mode or entry type.
184
-
185
-
186
- # Get valid fields for the specified Salesforce object
187
  sf_object = sf.__getattr__(object_name)
188
  schema = sf_object.describe()
189
  valid_fields = {field["name"] for field in schema["fields"]}
@@ -206,14 +206,14 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
206
  query_conditions.append(f"{model_field_name} = '{model_name}'")
207
  query_conditions.append(f"{product_field_name} = '{product_name}'")
208
 
209
- query = f"SELECT Id, {field_name} FROM {object_name} WHERE {' OR '.join(query_conditions)} LIMIT 1"
210
  response = sf.query(query)
211
 
212
  if response["records"]:
213
  record_id = response["records"][0]["Id"]
214
- updated_quantity = quantity # Overwrite the quantity
215
- sf_object.update(record_id, {field_name: updated_quantity})
216
- return f"✅ Updated record for product '{product_name}' ({model_name}) in {object_name}. New {field_name}: {updated_quantity}."
217
  else:
218
  return f"❌ No matching record found for product '{product_name}' ({model_name}) in {object_name}."
219
 
@@ -226,6 +226,7 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
226
 
227
  except Exception as e:
228
  return f"❌ Error interacting with Salesforce: {str(e)}"
 
229
  # Function to pull structured data from Salesforce and display as a table
230
  def pull_data_from_salesforce():
231
  try:
@@ -322,5 +323,4 @@ def app():
322
  ], ["📥 OCR Processing", "📊 Salesforce Data Export"])
323
 
324
  if __name__ == "__main__":
325
- app().launch(share=True)
326
-
 
 
1
  import os
2
  from paddleocr import PaddleOCR
3
  from PIL import Image
 
164
  field_names = []
165
  product_field_name = "Product_Name__c"
166
  model_field_name = "Model_Name__c" # Correct field for model name
167
+
168
  if mode == "Entry":
169
  if entry_type == "Sales":
170
  object_name = "VENKATA_RAMANA_MOTORS__c"
 
172
  elif entry_type == "Non-Sales":
173
  object_name = "UNBILLING_DATA__c"
174
  field_name = "TotalQuantity__c"
175
+ elif mode == "Exit":
176
+ if entry_type == "Sales":
177
+ object_name = "Inventory_Management__c"
178
+ field_names = ["Quantity_Sold__c", "LeftStock__c"]
179
+ elif entry_type == "Non-Sales":
180
+ object_name = "Un_Billable__c"
181
+ field_name = "Sold_Out__c"
182
+
183
+ if not object_name or (not field_name and not field_names):
184
+ return "Invalid mode or entry type."
185
+
186
+ # Get valid fields for the specified Salesforce object
187
  sf_object = sf.__getattr__(object_name)
188
  schema = sf_object.describe()
189
  valid_fields = {field["name"] for field in schema["fields"]}
 
206
  query_conditions.append(f"{model_field_name} = '{model_name}'")
207
  query_conditions.append(f"{product_field_name} = '{product_name}'")
208
 
209
+ query = f"SELECT Id, {', '.join(field_names)} FROM {object_name} WHERE {' OR '.join(query_conditions)} LIMIT 1"
210
  response = sf.query(query)
211
 
212
  if response["records"]:
213
  record_id = response["records"][0]["Id"]
214
+ updated_fields = {field: quantity for field in field_names}
215
+ sf_object.update(record_id, updated_fields)
216
+ return f"✅ Updated record for product '{product_name}' ({model_name}) in {object_name}. Updated fields: {updated_fields}."
217
  else:
218
  return f"❌ No matching record found for product '{product_name}' ({model_name}) in {object_name}."
219
 
 
226
 
227
  except Exception as e:
228
  return f"❌ Error interacting with Salesforce: {str(e)}"
229
+
230
  # Function to pull structured data from Salesforce and display as a table
231
  def pull_data_from_salesforce():
232
  try:
 
323
  ], ["📥 OCR Processing", "📊 Salesforce Data Export"])
324
 
325
  if __name__ == "__main__":
326
+ app().launch(share=True)