| from simple_salesforce import Salesforce | |
| import pandas as pd | |
| import os | |
| sf = Salesforce(username=os.getenv("SF_USERNAME"), | |
| password=os.getenv("SF_PASSWORD"), | |
| security_token=os.getenv("SF_TOKEN")) | |
| def push_data_to_salesforce(df, mode, entry_type): | |
| object_name = "Inventory_Entry__c" if mode == "Entry" else "Inventory_Exit__c" | |
| for _, row in df.iterrows(): | |
| try: | |
| sf.__getattr__(object_name).create({ | |
| "Product_Name__c": row["Product Name"], | |
| "Product_Model__c": row["Model"], | |
| "Horsepower__c": row["HP"], | |
| "Stage__c": row["Stage"], | |
| "Entry_Type__c": entry_type, | |
| "Price__c": row["Price"] | |
| }) | |
| except Exception as e: | |
| return f"Error pushing to Salesforce: {e}" | |
| return "β Data successfully pushed to Salesforce." | |
| def fetch_inventory_data(): | |
| query = "SELECT Product_Name__c, Stock__c FROM Inventory__c" | |
| result = sf.query_all(query) | |
| records = result["records"] | |
| return pd.DataFrame([{"Product": r["Product_Name__c"], "Stock": r["Stock__c"]} for r in records]) | |