Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,14 +60,13 @@ def insert_reconciliation_to_salesforce(df, sf):
|
|
| 60 |
return f"Inserted {inserted_count} records into Salesforce"
|
| 61 |
|
| 62 |
def generate_suggestion(row):
|
| 63 |
-
if row['
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
return "No action needed."
|
| 71 |
|
| 72 |
def reconcile_materials(csv_file):
|
| 73 |
if isinstance(csv_file, str):
|
|
@@ -113,10 +112,10 @@ def reconcile_materials(csv_file):
|
|
| 113 |
# Enforce anomaly for deviation beyond 15%
|
| 114 |
df.loc[df['Deviation'].abs() > 15, 'Anomaly'] = -1
|
| 115 |
|
| 116 |
-
# AI Suggestions & Status
|
| 117 |
df['AI_Suggestion'] = df.apply(generate_suggestion, axis=1)
|
| 118 |
df['Reconciliation_Status'] = df.apply(
|
| 119 |
-
lambda row: 'Flagged' if
|
| 120 |
axis=1
|
| 121 |
)
|
| 122 |
|
|
|
|
| 60 |
return f"Inserted {inserted_count} records into Salesforce"
|
| 61 |
|
| 62 |
def generate_suggestion(row):
|
| 63 |
+
if row['Deviation'] > 15:
|
| 64 |
+
excess = row['Used_Quantity'] - row['Planned_Quantity']
|
| 65 |
+
return f"Overuse Alert: Reduce future orders by {excess:.0f} units of {row['Material_Type']}."
|
| 66 |
+
elif row['Deviation'] < -15:
|
| 67 |
+
surplus = abs(row['Planned_Quantity'] - row['Used_Quantity'])
|
| 68 |
+
return f"Surplus Detected: {surplus:.0f} units unused. Consider reducing future orders."
|
| 69 |
+
return "Usage as planned. No action needed."
|
|
|
|
| 70 |
|
| 71 |
def reconcile_materials(csv_file):
|
| 72 |
if isinstance(csv_file, str):
|
|
|
|
| 112 |
# Enforce anomaly for deviation beyond 15%
|
| 113 |
df.loc[df['Deviation'].abs() > 15, 'Anomaly'] = -1
|
| 114 |
|
| 115 |
+
# AI Suggestions & Status (updated block)
|
| 116 |
df['AI_Suggestion'] = df.apply(generate_suggestion, axis=1)
|
| 117 |
df['Reconciliation_Status'] = df.apply(
|
| 118 |
+
lambda row: 'Flagged' if abs(row['Deviation']) > 15 else 'Complete',
|
| 119 |
axis=1
|
| 120 |
)
|
| 121 |
|