VijayPulmamidi commited on
Commit
ddfdc56
·
verified ·
1 Parent(s): f51be9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
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['Anomaly'] == -1 or abs(row['Deviation']) > 15:
64
- if row['Deviation'] < -15:
65
- shortage = abs(row['Planned_Quantity'] - row['Used_Quantity'])
66
- return f"Shortage: Order {shortage:.0f} more units of {row['Material_Type']}."
67
- elif row['Deviation'] > 15:
68
- excess = row['Used_Quantity'] - row['Planned_Quantity']
69
- return f"Excess: Reduce future orders by {excess:.0f} units of {row['Material_Type']}."
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 row['Anomaly'] == -1 or abs(row['Deviation']) > 15 else 'Complete',
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