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 <noreply@anthropic.com>
This commit is contained in:
JasonFraser 2026-08-25 13:57:01 -04:00
parent 65062f6f36
commit c32ab5984e
1 changed files with 14 additions and 5 deletions

View File

@ -82,14 +82,23 @@ def resolve_donor(raw_donor, merge_map):
return "General" if canonical == "General" else canonical 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): def full_file_balance(tb_df):
""" """
Sum every row's Planeterra Foundation value across the WHOLE file Sum every row's combined entity total across the WHOLE file (not
(not just revenue/expense rows) - a complete, correctly-exported just revenue/expense rows) - a complete, correctly-exported trial
trial balance nets to zero across all accounts. Used as an upload balance nets to zero across all accounts. Used as an upload
integrity check, independent of the revenue/expense filtering below. 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): 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["donor"] = parsed.apply(lambda t: resolve_donor(t[1], merge_map))
df["category"] = df[category_col].fillna("(Uncategorized)") 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 df["amount"] = -raw_amount if flip_sign else raw_amount
# Grouped by donor -> project code -> category only, deliberately not # Grouped by donor -> project code -> category only, deliberately not