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