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.
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:
Result
Output of the test case: 1,260 synthetic invoices worth ARS 500.2 M (March to August 2026).
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.
