pavansuresh commited on
Commit
0a810c4
·
verified ·
1 Parent(s): f9148c7

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +2 -12
utils.py CHANGED
@@ -115,7 +115,7 @@ def extract_key_value_pairs(pdf_path):
115
  except Exception as e:
116
  return None, str(e)
117
 
118
- # ✅ Updated to force map Start/End Dates to correct Salesforce fields
119
  def map_fields(extracted_data, object_fields):
120
  try:
121
  mappings = {}
@@ -127,16 +127,6 @@ def map_fields(extracted_data, object_fields):
127
  if key.lower() in ["name", "email"]:
128
  continue # Skip these
129
 
130
- # ✅ Hardcoded mappings
131
- if key == "Agreement Start Date" and "StartDate" in object_fields:
132
- mappings[key] = "StartDate"
133
- confidence_scores[key] = 1.0
134
- continue
135
- if key == "Agreement End Date" and "EndDate" in object_fields:
136
- mappings[key] = "EndDate"
137
- confidence_scores[key] = 1.0
138
- continue
139
-
140
  best_match = difflib.get_close_matches(key, object_fields, n=1, cutoff=0.0)
141
  if best_match:
142
  matched_field = best_match[0]
@@ -188,4 +178,4 @@ def attach_pdf(sf, record_id, pdf_path):
188
  def log_failure(pdf_path, object_name, error):
189
  with open("failures.json", "a") as f:
190
  json.dump({"pdf": pdf_path, "object": object_name, "error": error}, f)
191
- f.write("\n")
 
115
  except Exception as e:
116
  return None, str(e)
117
 
118
+ # ✅ FIXED: Use original key as mapping key (not value)
119
  def map_fields(extracted_data, object_fields):
120
  try:
121
  mappings = {}
 
127
  if key.lower() in ["name", "email"]:
128
  continue # Skip these
129
 
 
 
 
 
 
 
 
 
 
 
130
  best_match = difflib.get_close_matches(key, object_fields, n=1, cutoff=0.0)
131
  if best_match:
132
  matched_field = best_match[0]
 
178
  def log_failure(pdf_path, object_name, error):
179
  with open("failures.json", "a") as f:
180
  json.dump({"pdf": pdf_path, "object": object_name, "error": error}, f)
181
+ f.write("\n")