From 87ca8d585fa56679d89f8ebeae8f103a60bfcf74 Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Tue, 25 Aug 2026 13:09:21 -0400 Subject: [PATCH] Simplify donor sheet detail rows, drop redundant text in column A Project code and category were already their own structured columns (C, D), so repeating them as text in column A (a " C&B" header row, then " Corporate Supporters" per category) was redundant. Detail rows now leave column A blank; each project code's rows are followed directly by its " Subtotal" row, one row shorter per project code than before. Re-verified every formula in a full regenerated report still resolves correctly and matches the same grand totals as before this change. Co-Authored-By: Claude Sonnet 5 --- app/tools/donor_report/logic.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/tools/donor_report/logic.py b/app/tools/donor_report/logic.py index 3cfecb5..2d4efe4 100644 --- a/app/tools/donor_report/logic.py +++ b/app/tools/donor_report/logic.py @@ -155,8 +155,8 @@ def _write_cell(ws, row, col, value, bold=False, number_format=None): def _rows_needed(df): """How many rows a section (Revenue or Expenses) needs: one header - row per account, then per SLOB one header row + one row per category - + one subtotal row.""" + row per account, then per project code (SLOB) one row per category + plus one subtotal row.""" if df.empty: return 0 needed = 0 @@ -164,7 +164,7 @@ def _rows_needed(df): needed += 1 acct_df = df[df["account_code"] == code] for slob in acct_df["slob"].unique(): - needed += 1 + len(acct_df[acct_df["slob"] == slob]) + 1 + needed += len(acct_df[acct_df["slob"] == slob]) + 1 return needed @@ -185,10 +185,13 @@ def _adjust_block(ws, block_start, available, needed): def _write_section(ws, start_row, df): """ - Write Account -> SLOB -> Category rows starting at start_row, with a - SUM formula (over its own category rows) on each SLOB subtotal row. - Returns the list of subtotal cell coordinates (for the section - total's own SUM formula) and this section's raw total. + Write Account -> Category rows starting at start_row, subtotaled by + project code (SLOB), with a SUM formula (over its own category rows) + on each subtotal row. Project code and category are already their + own columns (C, D), so detail rows leave column A blank rather than + repeating that text - only the account header and each subtotal row + get an A-column label. Returns the list of subtotal cell coordinates + (for the section total's own SUM formula) and this section's raw total. """ row = start_row subtotal_cells = [] @@ -205,13 +208,10 @@ def _write_section(ws, start_row, df): for slob in sorted(acct_df["slob"].unique()): slob_df = acct_df[acct_df["slob"] == slob] slob_label = slob or "(No project code)" - _write_cell(ws, row, 1, f" {slob_label}", bold=False) - row += 1 cat_first_row = row for _, r in slob_df.sort_values("category").iterrows(): amount = round(r["amount"], 2) - _write_cell(ws, row, 1, f" {r['category']}", bold=False) _write_cell(ws, row, 2, amount, bold=False, number_format=AMOUNT_FORMAT) _write_cell(ws, row, 3, slob_label, bold=False) _write_cell(ws, row, 4, r["category"], bold=False) @@ -219,7 +219,7 @@ def _write_section(ws, start_row, df): row += 1 cat_last_row = row - 1 - _write_cell(ws, row, 1, f" {slob_label} Subtotal", bold=True) + _write_cell(ws, row, 1, f"{slob_label} Subtotal", bold=True) c = ws.cell(row=row, column=2, value=f"=SUM(B{cat_first_row}:B{cat_last_row})") c.font = BOLD_FONT c.number_format = AMOUNT_FORMAT