From c32ab5984e5bf9f6cee89f4ffb53669aeb02b344 Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Tue, 25 Aug 2026 13:57:01 -0400 Subject: [PATCH] Include the Planeterra International Foundation Ltd entity column Amounts were only pulling from "Planeterra Foundation" (column D); "Planeterra International Foundation Ltd" (column E) is now added in too via a shared _entity_total() helper, used both for the per-row amounts and the full-file balance integrity check. Eliminations (column F) stays excluded - it's zero on every row in both sample files, so D+E already equals the trial balance's own precomputed "Total" (D+E+F) column; nothing currently depends on including it. Verified against the real files: revenue moves from 4,384,170.35 to 5,338,866.02 (exactly sum(D)+sum(E) on the filtered rows) and expense from 3,611,064.64 to 3,743,572.26, matching hand-calculated sums before touching the report generator. Re-ran the full formula verification (every Total Revenue/Expenses/Surplus cell across all 12 donor sheets plus the Summary sheet's cross-sheet references) with no mismatches. Co-Authored-By: Claude Sonnet 5 --- app/tools/donor_report/logic.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/tools/donor_report/logic.py b/app/tools/donor_report/logic.py index e8c8303..115e6ba 100644 --- a/app/tools/donor_report/logic.py +++ b/app/tools/donor_report/logic.py @@ -82,14 +82,23 @@ def resolve_donor(raw_donor, merge_map): return "General" if canonical == "General" else canonical +def _entity_total(df): + """Combined amount across both entities - Planeterra Foundation and + Planeterra International Foundation Ltd. Eliminations is excluded: + it's zero on every row in the sample data, and D+E already matches + the trial balance's own precomputed "Total" (D+E+F) column as a + result, so there's nothing it would currently change.""" + return df["Planeterra Foundation"].fillna(0) + df["Planeterra International Foundation Ltd"].fillna(0) + + def full_file_balance(tb_df): """ - Sum every row's Planeterra Foundation value across the WHOLE file - (not just revenue/expense rows) - a complete, correctly-exported - trial balance nets to zero across all accounts. Used as an upload + Sum every row's combined entity total across the WHOLE file (not + just revenue/expense rows) - a complete, correctly-exported trial + balance nets to zero across all accounts. Used as an upload integrity check, independent of the revenue/expense filtering below. """ - return round(tb_df["Planeterra Foundation"].fillna(0).sum(), 2) + return round(_entity_total(tb_df).sum(), 2) def _process_side(tb_df, account_codes, category_col, flip_sign, merge_map): @@ -101,7 +110,7 @@ def _process_side(tb_df, account_codes, category_col, flip_sign, merge_map): df["donor"] = parsed.apply(lambda t: resolve_donor(t[1], merge_map)) df["category"] = df[category_col].fillna("(Uncategorized)") - raw_amount = df["Planeterra Foundation"].fillna(0) + raw_amount = _entity_total(df) df["amount"] = -raw_amount if flip_sign else raw_amount # Grouped by donor -> project code -> category only, deliberately not