Update app.py
Browse files
app.py
CHANGED
|
@@ -150,80 +150,70 @@ 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
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
else: # β If no match, create a new record
|
| 212 |
-
filtered_attributes = {ATTRIBUTE_MAPPING[key]: value for key, value in attributes.items() if ATTRIBUTE_MAPPING[key] in valid_fields}
|
| 213 |
-
filtered_attributes[field_name] = quantity
|
| 214 |
-
sf.__getattr__(object_name).create(filtered_attributes)
|
| 215 |
-
|
| 216 |
-
return f"π Created new record for '{product_name}' in {object_name} with {field_name}: {quantity}."
|
| 217 |
-
|
| 218 |
-
# π Entry Mode: Always Create a New Record
|
| 219 |
-
filtered_attributes = {ATTRIBUTE_MAPPING[key]: value for key, value in attributes.items() if ATTRIBUTE_MAPPING[key] in valid_fields}
|
| 220 |
-
filtered_attributes[field_name] = quantity
|
| 221 |
-
sf.__getattr__(object_name).create(filtered_attributes)
|
| 222 |
|
| 223 |
-
|
|
|
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
|
| 228 |
# Function to pull structured data from Salesforce and display as a table
|
| 229 |
def pull_data_from_salesforce():
|
|
|
|
| 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():
|