gopichandra commited on
Commit
2a5f2e4
·
verified ·
1 Parent(s): ac8bc3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -60
app.py CHANGED
@@ -150,71 +150,76 @@ def filter_valid_attributes(attributes, valid_fields):
150
  return {ATTRIBUTE_MAPPING[key]: value for key, value in attributes.items() if ATTRIBUTE_MAPPING[key] in valid_fields}
151
 
152
  #📊 Function to interact with Salesforce based on mode and type
153
- def export_entry_sales(sf, product_data):
154
- """
155
- Exports data to VENKATA_RAMANA_MOTORS__c and UNBILLING_DATA__c objects when entry and sales are clicked.
156
- """
157
- venkata_data = {
158
- 'Product_Name__c': product_data['Product_Name__c'],
159
- 'Modal_Name__c': product_data['Modal_Name__c'],
160
- 'Quantity__c': product_data['Quantity']
161
- }
162
- sf.VENKATA_RAMANA_MOTORS__c.create(venkata_data)
163
-
164
- unbilling_data = {
165
- 'Product_Name__c': product_data['Product_Name__c'],
166
- 'Modal_Name__c': product_data['Modal_Name__c'],
167
- 'TotalQuantity__c': product_data['Quantity']
168
  }
169
- sf.UNBILLING_DATA__c.create(unbilling_data)
170
-
171
- print("Entry and Sales data exported successfully.")
172
 
173
- def update_exit_sales(sf, product_data):
174
- """
175
- Updates Inventory_Management__c and Un_Billable__c objects when exit mode sales is clicked.
176
- """
177
- # Find matching record in Inventory_Management__c
178
- inventory_records = sf.query(f"""
179
- SELECT Id, Quantity_Sold__c FROM Inventory_Management__c
180
- WHERE Product_Name__c = '{product_data['Product_Name__c']}'
181
- OR Modal_Name__c = '{product_data['Modal_Name__c']}'
182
- """)
183
-
184
- if inventory_records['records']:
185
- inventory_id = inventory_records['records'][0]['Id']
186
- new_quantity_sold = inventory_records['records'][0]['Quantity_Sold__c'] + product_data['Quantity']
187
- sf.Inventory_Management__c.update(inventory_id, {'Quantity_Sold__c': new_quantity_sold})
188
- print("Inventory Management updated successfully.")
189
-
190
- # Find matching record in Un_Billable__c
191
- unbillable_records = sf.query(f"""
192
- SELECT Id, Sold_Out__c FROM Un_Billable__c
193
- WHERE Product_Name__c = '{product_data['Product_Name__c']}'
194
- OR Model_Name__c = '{product_data['Modal_Name__c']}'
195
- """)
196
-
197
- if unbillable_records['records']:
198
- unbillable_id = unbillable_records['records'][0]['Id']
199
- new_sold_out_quantity = unbillable_records['records'][0]['Sold_Out__c'] + product_data['Quantity']
200
- sf.Un_Billable__c.update(unbillable_id, {'Sold_Out__c': new_sold_out_quantity})
201
- print("Un_Billable updated successfully.")
202
-
203
- # Example usage
204
- sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token')
205
-
206
- product_data = {
207
- 'Product_Name__c': 'Example Product',
208
- 'Modal_Name__c': 'Example Model',
209
- 'Quantity': 10
210
- }
211
 
212
- # When clicking entry and sales
213
- export_entry_sales(sf, product_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
- # When clicking exit mode sales
216
- update_exit_sales(sf, product_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  # Function to pull structured data from Salesforce and display as a table
219
  def pull_data_from_salesforce():
220
  try:
 
150
  return {ATTRIBUTE_MAPPING[key]: value for key, value in attributes.items() if ATTRIBUTE_MAPPING[key] in valid_fields}
151
 
152
  #📊 Function to interact with Salesforce based on mode and type
153
+ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
154
+ try:
155
+ sf = Salesforce(
156
+ username=SALESFORCE_USERNAME,
157
+ password=SALESFORCE_PASSWORD,
158
+ security_token=SALESFORCE_SECURITY_TOKEN
159
+ )
160
+ def export_entry_sales(sf, quantity):
161
+ data = {
162
+ 'Quantity__c': quantity
 
 
 
 
 
163
  }
164
+ sf.VENKATA_RAMANA_MOTORS__c.create(data)
165
+ print("Exported to VENKATA_RAMANA_MOTORS__c successfully")
 
166
 
167
+ def export_entry_nonsales(sf, quantity):
168
+ data = {
169
+ 'TotalQuantity__c': quantity
170
+ }
171
+ sf.UNBILLING_DATA__c.create(data)
172
+ print("Exported to UNBILLING_DATA__c successfully")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
+ def export_exit_sales(sf, product_name, quantity):
175
+ query = f"SELECT Id, Quantity_Sold__c FROM Inventory_Management__c WHERE Name = '{product_name}' LIMIT 1"
176
+ result = sf.query(query)
177
+ if result['records']:
178
+ record_id = result['records'][0]['Id']
179
+ updated_quantity = result['records'][0]['Quantity_Sold__c'] + int(quantity)
180
+ sf.Inventory_Management__c.update(record_id, {'Quantity_Sold__c': updated_quantity})
181
+ print("Updated Inventory_Management__c successfully")
182
+ else:
183
+ data = {
184
+ 'Name': product_name,
185
+ 'Quantity_Sold__c': quantity
186
+ }
187
+ sf.Inventory_Management__c.create(data)
188
+ print("Created new record in Inventory_Management__c successfully")
189
 
190
+ def export_exit_nonsales(sf, product_name, quantity):
191
+ query = f"SELECT Id, Sold_Out__c FROM Un_Billable__c WHERE Name = '{product_name}' LIMIT 1"
192
+ result = sf.query(query)
193
+ if result['records']:
194
+ record_id = result['records'][0]['Id']
195
+ updated_quantity = result['records'][0]['Sold_Out__c'] + int(quantity)
196
+ sf.Un_Billable__c.update(record_id, {'Sold_Out__c': updated_quantity})
197
+ print("Updated Un_Billable__c successfully")
198
+ else:
199
+ data = {
200
+ 'Name': product_name,
201
+ 'Sold_Out__c': quantity
202
+ }
203
+ sf.Un_Billable__c.create(data)
204
+ print("Created new record in Un_Billable__c successfully")
205
 
206
+ def main():
207
+ sf = connect_to_salesforce()
208
+
209
+ action = input("Enter action (entry_sales, entry_nonsales, exit_sales, exit_nonsales): ")
210
+ product_name = input("Enter product/model name: ")
211
+ quantity = input("Enter quantity: ")
212
+
213
+ if action == "entry_sales":
214
+ export_entry_sales(sf, quantity)
215
+ elif action == "entry_nonsales":
216
+ export_entry_nonsales(sf, quantity)
217
+ elif action == "exit_sales":
218
+ export_exit_sales(sf, product_name, quantity)
219
+ elif action == "exit_nonsales":
220
+ export_exit_nonsales(sf, product_name, quantity)
221
+ else:
222
+ print("Invalid action")
223
  # Function to pull structured data from Salesforce and display as a table
224
  def pull_data_from_salesforce():
225
  try: