Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -239,7 +239,8 @@ def pull_data_from_salesforce():
|
|
| 239 |
)
|
| 240 |
|
| 241 |
query_inventory = "SELECT Product_Name__c, Current_Stocks__c, soldstock__c FROM Inventory_Management__c LIMIT 100"
|
| 242 |
-
query_unbillable
|
|
|
|
| 243 |
|
| 244 |
response_inventory = sf.query_all(query_inventory)
|
| 245 |
response_unbillable = sf.query_all(query_unbillable)
|
|
@@ -250,35 +251,25 @@ def pull_data_from_salesforce():
|
|
| 250 |
if not records_inventory and not records_unbillable:
|
| 251 |
return "No data found in Salesforce.", None, None, None
|
| 252 |
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
|
| 257 |
# Rename columns for better readability
|
| 258 |
-
|
| 259 |
-
"Product_Name__c": "Product Name
|
| 260 |
-
"
|
| 261 |
-
"soldstock__c": "Sold Stock (Inventory)"
|
| 262 |
-
}, inplace=True)
|
| 263 |
-
|
| 264 |
-
df_unbillable.rename(columns={
|
| 265 |
-
"Product_Name__c": "Product Name (Unbillable)",
|
| 266 |
"Model_Name__c": "Model Name (Unbillable)",
|
| 267 |
-
"Current_Stocks__c": "Current Stocks
|
| 268 |
-
"soldstock__c": "Sold Stock
|
| 269 |
}, inplace=True)
|
| 270 |
|
| 271 |
-
# Combine the DataFrames side by side
|
| 272 |
-
df_combined = pd.concat([df_inventory, df_unbillable], axis=1)
|
| 273 |
-
|
| 274 |
excel_path = "salesforce_data.xlsx"
|
| 275 |
-
|
| 276 |
|
| 277 |
# Generate interactive vertical bar graph using Matplotlib
|
| 278 |
fig, ax = plt.subplots(figsize=(12, 8))
|
| 279 |
-
|
| 280 |
-
df_inventory.plot(kind='bar', x="Product Name (Inventory)", y="Current Stocks (Inventory)", ax=ax, legend=True, color='blue', position=0, width=width)
|
| 281 |
-
df_unbillable.plot(kind='bar', x="Product Name (Unbillable)", y="Current Stocks (Unbillable)", ax=ax, legend=True, color='red', position=1, width=width)
|
| 282 |
ax.set_title("Stock Distribution by Product Name")
|
| 283 |
ax.set_xlabel("Product Name")
|
| 284 |
ax.set_ylabel("Current Stocks")
|
|
@@ -289,7 +280,7 @@ def pull_data_from_salesforce():
|
|
| 289 |
buffer.seek(0)
|
| 290 |
img = Image.open(buffer)
|
| 291 |
|
| 292 |
-
return "Data successfully retrieved.",
|
| 293 |
except Exception as e:
|
| 294 |
return f"Error fetching data: {str(e)}", None, None, None
|
| 295 |
|
|
@@ -343,4 +334,8 @@ def app():
|
|
| 343 |
], ["📥 OCR Processing", "📊 Salesforce Data Export"])
|
| 344 |
|
| 345 |
if __name__ == "__main__":
|
| 346 |
-
app().launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
)
|
| 240 |
|
| 241 |
query_inventory = "SELECT Product_Name__c, Current_Stocks__c, soldstock__c FROM Inventory_Management__c LIMIT 100"
|
| 242 |
+
query_unbillable= "SELECT Product_Name__c, Current_Stock__c, soldstock__c FROM Un_Billable__c LIMIT 100"
|
| 243 |
+
|
| 244 |
|
| 245 |
response_inventory = sf.query_all(query_inventory)
|
| 246 |
response_unbillable = sf.query_all(query_unbillable)
|
|
|
|
| 251 |
if not records_inventory and not records_unbillable:
|
| 252 |
return "No data found in Salesforce.", None, None, None
|
| 253 |
|
| 254 |
+
records = records_inventory + records_unbillable
|
| 255 |
+
df = pd.DataFrame(records)
|
| 256 |
+
df = df.drop(columns=['attributes'], errors='ignore')
|
| 257 |
|
| 258 |
# Rename columns for better readability
|
| 259 |
+
df.rename(columns={
|
| 260 |
+
"Product_Name__c": "Product Name",
|
| 261 |
+
"Modal_Name__c": "Model Name (Inventory)",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
"Model_Name__c": "Model Name (Unbillable)",
|
| 263 |
+
"Current_Stocks__c": "Current Stocks",
|
| 264 |
+
"soldstock__c": "Sold Stock"
|
| 265 |
}, inplace=True)
|
| 266 |
|
|
|
|
|
|
|
|
|
|
| 267 |
excel_path = "salesforce_data.xlsx"
|
| 268 |
+
df.to_excel(excel_path, index=False)
|
| 269 |
|
| 270 |
# Generate interactive vertical bar graph using Matplotlib
|
| 271 |
fig, ax = plt.subplots(figsize=(12, 8))
|
| 272 |
+
df.plot(kind='bar', x="Product Name", y="Current Stocks", ax=ax, legend=False)
|
|
|
|
|
|
|
| 273 |
ax.set_title("Stock Distribution by Product Name")
|
| 274 |
ax.set_xlabel("Product Name")
|
| 275 |
ax.set_ylabel("Current Stocks")
|
|
|
|
| 280 |
buffer.seek(0)
|
| 281 |
img = Image.open(buffer)
|
| 282 |
|
| 283 |
+
return "Data successfully retrieved.", df, excel_path, img
|
| 284 |
except Exception as e:
|
| 285 |
return f"Error fetching data: {str(e)}", None, None, None
|
| 286 |
|
|
|
|
| 334 |
], ["📥 OCR Processing", "📊 Salesforce Data Export"])
|
| 335 |
|
| 336 |
if __name__ == "__main__":
|
| 337 |
+
app().launch(share=True)
|
| 338 |
+
|
| 339 |
+
if __name__ == "__main__":
|
| 340 |
+
app().launch(share=True)
|
| 341 |
+
|