Compare financial amounts (total, pretax, tax).
(gt: dict, agent: dict, tolerance: float)
| 207 | |
| 208 | |
| 209 | def compare_financials(gt: dict, agent: dict, tolerance: float) -> dict: |
| 210 | """Compare financial amounts (total, pretax, tax).""" |
| 211 | gt_details = gt.get("Invoice Details") or {} |
| 212 | agent_details = agent.get("Invoice Details") or {} |
| 213 | |
| 214 | fields = { |
| 215 | "Invoice Total": ("Invoice Total", tolerance), |
| 216 | "Pretax Total": ("Pretax Total", tolerance), |
| 217 | "Tax Amount": ("Tax Amount", tolerance), |
| 218 | } |
| 219 | |
| 220 | results = {} |
| 221 | all_match = True |
| 222 | |
| 223 | for label, (field_name, tol) in fields.items(): |
| 224 | gt_val = gt_details.get(field_name, "") |
| 225 | agent_val = agent_details.get(field_name, "") |
| 226 | match = amounts_match(gt_val, agent_val, tol) |
| 227 | if not match: |
| 228 | all_match = False |
| 229 | |
| 230 | results[label] = { |
| 231 | "ground_truth": gt_val, |
| 232 | "agent": agent_val, |
| 233 | "match": match, |
| 234 | } |
| 235 | |
| 236 | # Currency |
| 237 | gt_currency = gt_details.get("Currency", "") |
| 238 | agent_currency = agent_details.get("Currency", "") |
| 239 | currency_match = normalize_string(gt_currency) == normalize_string( |
| 240 | agent_currency |
| 241 | ) |
| 242 | results["Currency"] = { |
| 243 | "ground_truth": gt_currency, |
| 244 | "agent": agent_currency, |
| 245 | "match": currency_match, |
| 246 | } |
| 247 | if not currency_match: |
| 248 | all_match = False |
| 249 | |
| 250 | results["all_match"] = all_match |
| 251 | return results |
| 252 | |
| 253 | |
| 254 | def compare_vendor(gt: dict, agent: dict) -> dict: |
no test coverage detected