All projects
Case study · synthetic data Updated: November 2026

No wrong invoice reaches the payment run.

An automated control for the payables team of a fictional Argentine company: it validates CUITs, matches invoice, purchase order and goods receipt, and hands over an exception list with the reason for each one.

PythonpandaspytestExcelCUIT / IVA / CAE3-way match
IndustryShared services
My roleRules, analysis and QA
Volume1,260 invoices
ValidationControl totals + 7 tests
Invoice control summary: states and rules

Context

A shared-services team receives hundreds of supplier invoices a month. Most are fine. The costly ones are few: an invoice keyed twice, more units than were received, a price that drifted above the purchase order, a mistyped CUIT, IVA that does not add up.

Finding them by eye is slow and depends on who is reviewing. And they usually surface after the money has left.

Approach

I wrote twelve rules in business language, each with a code, an action (block or review) and a threshold finance can change without touching the logic. Every invoice then lands in one of three states: ready to pay, needs review or blocked.

Blocks paymentNeeds review
R01Invalid CUIT check digit10
R02Supplier not in master18
R03Exact duplicate14
R04Possible duplicate (7 days)6
R05Wrong IVA rate or amount12
R06Total ≠ net + IVA + other8
R07No PO above ARS 250,00010
R08Price > 2 % above PO18
R09Qty invoiced > received12
R10Invoice type vs tax status8
R11CAE missing or expired9
R12Inconsistent dates6

Rules overlap on purpose: a mistyped CUIT (R01) is also missing from the supplier master (R02). That is why the per-rule total is higher than the number of flagged invoices.

# src/apcontrol/rules.py: thresholds finance can edit
IVA_RATES = {0.21, 0.105, 0.27, 0.0}
PRICE_TOLERANCE = 0.02      # 2 % above the purchase order
AMOUNT_TOLERANCE = 0.01     # ARS rounding
NO_PO_THRESHOLD = 250_000   # ARS: above this, a PO is required
POSSIBLE_DUP_DAYS = 7

How I know it is right

A payment control that is wrong is worse than none. So the process checks itself on every run:

Every invoice and every peso lands in exactly one state (otherwise the run stops)PASS
All 121 planted issues are caught by their rulePASS
No clean invoice is flaggedPASS
Joins with suppliers, POs and receipts never duplicate an invoicePASS

Result

Output of the test case: 1,260 synthetic invoices worth ARS 500.2 M (March to August 2026).

1,139ready to payARS 431.3 M
48need reviewARS 29.4 M
73blockedARS 39.4 M

The team stops reviewing every invoice: it reviews only the flagged ones, and each arrives with its reason written down.

Deliverables

  • exceptions.csv: one row per invoice with the rules it hit.
  • ap_review.xlsx: states, rules, exceptions and control totals, ready for the team.
  • Documented rule catalogue and 7 automated tests.
  • An interactive dashboard with filters by status and rule.
Next caseAI KPI report, verified