Brands selling into 7-Eleven (7-11) through a Thai distributor rarely receive the full invoice value. Rebates, promotion support, markdowns, returns and penalties come off the payment. Each line may be perfectly legitimate. The trouble is that many brands check only the total, months later, when the evidence for any single line is hard to find.
This post sets out a small, repeatable method: every deduction line gets matched to something you can point to, and anything unmatched lands on a short list for the monthly review. Background on what to ask a distributor for each month is here: https://www.flowupth.com/en/insights/distributor-monthly-review?utm_source=devto&utm_campaign=P503
What you need
Three inputs, kept as plain CSV files:
- Deduction statement from the distributor, one row per line, not a lump sum. If you only get a lump sum, the first fix is a conversation, not code.
- Your agreement terms turned into a lookup table: each clause that allows a deduction, its basis (percentage of what, per unit, fixed) and the period it applies to.
- Your event log: approved promotions with dates and areas, agreed returns, documented penalties.
Shape of the data
deductions.csv : line_id, period, type, amount, reference, area terms.csv : clause_id, type, basis, rate, valid_from, valid_to events.csv : event_id, type, start, end, area, approved_amount, approval_ref invoices.csv : period, area, net_sales type uses one shared vocabulary across all files, for example rebate, promo_support, markdown, return, penalty, other. Agreeing that vocabulary with the distributor once saves hours every month.
Matching rules
Each deduction line tries these in order and stops at the first match:
- Clause-based (for example a rebate): find a clause of the same type valid in that period, compute the expected amount from its basis, and compare.
- Event-based (promotion support, markdown, returns): find an approved event of the same type whose dates overlap the period and whose area matches.
- Documented penalty: there is a reference to a written notice.
Anything else is unmatched.
The script
import pandas as pd ded = pd.read_csv("deductions.csv", parse_dates=["period"]) terms = pd.read_csv("terms.csv", parse_dates=["valid_from", "valid_to"]) events = pd.read_csv("events.csv", parse_dates=["start", "end"]) sales = pd.read_csv("invoices.csv", parse_dates=["period"]) TOL = 0.02 # example tolerance only: 2% gap before a line is flagged def match(row): t = terms[(terms.type == row.type) & (terms.valid_from <= row.period) & (terms.valid_to >= row.period)] if not t.empty and t.iloc[0].basis == "pct_net_sales": base = sales[(sales.period == row.period) & (sales.area == row.area)].net_sales.sum() expected = base * t.iloc[0].rate gap = abs(row.amount - expected) / expected if expected else 1 return ("clause", t.iloc[0].clause_id, round(expected, 2), gap <= TOL) e = events[(events.type == row.type) & (events.area == row.area) & (events.start <= row.period + pd.offsets.MonthEnd(0)) & (events.end >= row.period)] if not e.empty: return ("event", e.iloc[0].event_id, e.iloc[0].approved_amount, row.amount <= e.iloc[0].approved_amount * (1 + TOL)) if row.type == "penalty" and isinstance(row.reference, str) and row.reference.strip(): return ("penalty_doc", row.reference, None, True) return ("unmatched", None, None, False) ded[["match_kind", "match_ref", "expected", "ok"]] = ded.apply( lambda r: pd.Series(match(r)), axis=1) review = ded[~ded.ok].sort_values("amount", ascending=False) review.to_csv("deductions_to_review.csv", index=False) print(ded.groupby(["type", "match_kind"]).amount.sum().round(0)) The basis handling is deliberately minimal. Real agreements may calculate rebates on different bases, apply tiers, or settle annually. Add a branch for each basis your terms actually use rather than forcing them into one formula.
Reading the output
-
ok = True: matched and within tolerance. No discussion needed. - Matched but not ok: right clause or event, wrong amount. Usually a base or rate disagreement. Bring the calculation, not just the number.
-
unmatched: no clause, no approved event, no document. These go first on the monthly agenda.
Example only, with made-up figures: if a month shows ten deduction lines and two are unmatched, the conversation is about those two lines and their references, which takes minutes rather than an afternoon arguing about a total.
Habits that make it work
- Run it every month, not at year end. Evidence is easiest to find while the period is fresh.
- Log approvals when you give them. Most "unmatched" lines turn out to be real promotions that nobody wrote down.
- Share the output with the distributor before the meeting. It turns a dispute into a reconciliation.
In our work at Flowup Thailand this sits next to the monthly stock and sell-out review: one tells you whether product is moving, the other whether the money from it is arriving as agreed.
Limits
Deduction types, bases and settlement timing differ by agreement and category, and nothing here describes any retailer's internal process. Treat the script as a skeleton to adapt, and check accounting treatment with your own finance team.