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 "<Project Code> 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 <noreply@anthropic.com>
This commit is contained in:
parent
8d2da18bfb
commit
87ca8d585f
|
|
@ -155,8 +155,8 @@ def _write_cell(ws, row, col, value, bold=False, number_format=None):
|
||||||
|
|
||||||
def _rows_needed(df):
|
def _rows_needed(df):
|
||||||
"""How many rows a section (Revenue or Expenses) needs: one header
|
"""How many rows a section (Revenue or Expenses) needs: one header
|
||||||
row per account, then per SLOB one header row + one row per category
|
row per account, then per project code (SLOB) one row per category
|
||||||
+ one subtotal row."""
|
plus one subtotal row."""
|
||||||
if df.empty:
|
if df.empty:
|
||||||
return 0
|
return 0
|
||||||
needed = 0
|
needed = 0
|
||||||
|
|
@ -164,7 +164,7 @@ def _rows_needed(df):
|
||||||
needed += 1
|
needed += 1
|
||||||
acct_df = df[df["account_code"] == code]
|
acct_df = df[df["account_code"] == code]
|
||||||
for slob in acct_df["slob"].unique():
|
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
|
return needed
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -185,10 +185,13 @@ def _adjust_block(ws, block_start, available, needed):
|
||||||
|
|
||||||
def _write_section(ws, start_row, df):
|
def _write_section(ws, start_row, df):
|
||||||
"""
|
"""
|
||||||
Write Account -> SLOB -> Category rows starting at start_row, with a
|
Write Account -> Category rows starting at start_row, subtotaled by
|
||||||
SUM formula (over its own category rows) on each SLOB subtotal row.
|
project code (SLOB), with a SUM formula (over its own category rows)
|
||||||
Returns the list of subtotal cell coordinates (for the section
|
on each subtotal row. Project code and category are already their
|
||||||
total's own SUM formula) and this section's raw total.
|
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
|
row = start_row
|
||||||
subtotal_cells = []
|
subtotal_cells = []
|
||||||
|
|
@ -205,13 +208,10 @@ def _write_section(ws, start_row, df):
|
||||||
for slob in sorted(acct_df["slob"].unique()):
|
for slob in sorted(acct_df["slob"].unique()):
|
||||||
slob_df = acct_df[acct_df["slob"] == slob]
|
slob_df = acct_df[acct_df["slob"] == slob]
|
||||||
slob_label = slob or "(No project code)"
|
slob_label = slob or "(No project code)"
|
||||||
_write_cell(ws, row, 1, f" {slob_label}", bold=False)
|
|
||||||
row += 1
|
|
||||||
|
|
||||||
cat_first_row = row
|
cat_first_row = row
|
||||||
for _, r in slob_df.sort_values("category").iterrows():
|
for _, r in slob_df.sort_values("category").iterrows():
|
||||||
amount = round(r["amount"], 2)
|
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, 2, amount, bold=False, number_format=AMOUNT_FORMAT)
|
||||||
_write_cell(ws, row, 3, slob_label, bold=False)
|
_write_cell(ws, row, 3, slob_label, bold=False)
|
||||||
_write_cell(ws, row, 4, r["category"], bold=False)
|
_write_cell(ws, row, 4, r["category"], bold=False)
|
||||||
|
|
@ -219,7 +219,7 @@ def _write_section(ws, start_row, df):
|
||||||
row += 1
|
row += 1
|
||||||
cat_last_row = 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 = ws.cell(row=row, column=2, value=f"=SUM(B{cat_first_row}:B{cat_last_row})")
|
||||||
c.font = BOLD_FONT
|
c.font = BOLD_FONT
|
||||||
c.number_format = AMOUNT_FORMAT
|
c.number_format = AMOUNT_FORMAT
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue