- New category/project reassignment system: when a TB category or
project has no home in the uploaded Budget file, two sequential
review gates (category_mapping, then project_mapping) let the user
fold it into an existing budget category/project (merging actuals
into the target row, project code preserved) or explicitly leave it
as-is - persisted to category_reassignment_map.csv/
project_reassignment_map.csv, editable any time via a standalone
Manage Mappings panel with inline dropdowns sourced from the stored
Budget file's own real categories/projects per account.
- Accounts 79000/81000 (FX revaluation) always collapse every category
under them into one fixed name, unconditionally.
- Fixed a live-formula bug the reassignment work exposed: Category
Summary's SUMIFS criteria were built from reassigned/collapsed
category text but pointed at the untouched raw TB sheets, so a
merged row's formula would silently evaluate to zero in real Excel.
Fixed by writing "Category (Applied)"/"Project (Applied)" columns
onto the Revenue TB/Expense TB sheet copies and pointing formulas at
those instead.
- A faithfully-styled, visible copy of the actual uploaded Budget file
("Budget (Original)") now replaces the old plain-data dump as what a
person sees first; the plain-data "Budget" sheet still powers every
live formula but is now hidden.
- Category Summary formatting: "Total Revenue"/"Project Costs"/"Net
Revenues" moved to the Category column; each 68020-82000 account
subtotal gets a "Total <name>" label; every major total/subtotal row
gets a top+bottom border; the Variance column conditionally formats
values below -$0.0001 in red.
- Two new reference sheets: "Reassignment Reference" (original-vs-
shown-as text for every actual reassignment/forced collapse) and
"GL Detail" (every GL Dump line tagged and sorted the same way
Category Summary groups its own rows) - both purely additive, neither
feeds any calculated figure.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HToTtpxzoxeugsa1Ve61gn
- Canonicalize category/project/account text before grouping so
case-only variants (e.g. "OffSite Meetings" vs "Offsite Meetings")
collapse to one row instead of producing two SUMIFS formulas that
double-count each other under Excel/Sheets' case-insensitive text
matching - this was the source of the reported mismatch.
- Add _assert_no_case_collisions as a build-time safety net; the old
Python-only reconciliation check couldn't catch this class of bug
since grouped-vs-source totals are mathematically equal regardless
of labeling. routes.py now returns a clean 400 if it ever fires.
- Reposition 68020 out of the project-level (Account>Category>Project)
section into the collapsed section with 70000+, so only 68010/68030
remain above the Project Costs subtotal, matching the reference
template.
- Rename the two output sheets to "1. Summary (Manual)" and
"Balance Sheet (FS)", updating the cross-sheet Net Income formula
reference to match.
- Explicitly set calcMode="auto" (in addition to openpyxl's default
fullCalcOnLoad) so edits to the TB sheets keep recalculating
dependent formulas after the first open, not just on it.
- Add a "Report vs. Source Files" comparison table to the results UI
showing Total Income/Expenses/Surplus side by side against figures
computed independently from the uploaded files.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
New tool at /financial-reports/, same two-file trial balance upload as
the donor report, generating a workbook built fresh with openpyxl
(no bundled Excel template - the sheets are constructed to match
fs.xlsx's own structure/formatting rather than adjusting a copy of it):
- Category Summary: mirrors "1. Summary (Manual)" from the reference
workbook - Account | Category | Project Code (full raw string,
unsplit) | Canada YTD | US YTD | Consolidation Adjustments (blank) |
Total YTD (formula) | Budget (header only, left blank for manual
formulas). Category-level subtotal rows (SUM formulas), sorted within
a category by strategic area then full project code. Total Revenue/
Total Expenses/Surplus as formulas summing the category subtotals.
- Balance Sheet: single-period snapshot matching "Balance Sheet (FS)"'s
labels/section order/Arial-11 formatting - the source file's
month-over-month and prior-year columns are static historical
snapshots that can't be regenerated from one trial balance upload, so
this is one consolidated (Canada+US) column for the current period.
Account-code-to-line-item mapping lives in
balance_sheet_account_map.csv (bind-mounted, same pattern as the
other tools' lookup tables), seeded from fs.xlsx's own N-S helper
columns. Net Assets/Unrestricted = Retained Earnings (36000) + CTA
(36300) + this period's computed Net Income - avoids needing prior-
period data since 36000 already carries the cumulative prior position.
- Arithmetic check back to the uploaded files: every run independently
re-sums Planeterra Foundation/Planeterra International Foundation Ltd
across the filtered revenue+expense rows and compares against the
Category Summary's own Canada/US totals, surfaced on both the results
screen and embedded in the workbook. The Balance Sheet's own
Assets-vs-Liabilities+NetAssets check is exposed the same way.
- UI: multi-file upload (auto-classifies revenue vs. expense by column
headers), checkboxes for which sections to include, report date,
report title, and a whole-dollars-vs-cents number format toggle.
Two real bugs found and fixed during testing, not just simplified logic:
- numpy.bool_ (from pandas comparisons) isn't JSON-serializable, unlike
native Python bool - silently 500'd the endpoint until wrapped.
- compute_balance_sheet() was concatenating both uploaded files before
summing Balance Sheet accounts - but both files are independently
complete trial balance exports (same non-P&L rows in both, just
tagged with a different category column), so this double-counted
every single Balance Sheet account by exactly 2x. Caught via a
balance_check that came out as -net_income instead of zero - too
precise to be a coincidence, traced it back to the concat.
Verified end to end against the real trial balance files: Category
Summary Canada/US reconciliation both MATCH exactly, and the Balance
Sheet balance_check is exactly 0.00 (Assets = Liabilities + Net
Assets). Independently re-resolved every formula (including the
53-term Total Expenses SUM) and confirmed all totals match the API
response: revenue 5,338,866.02 / expense 3,743,572.26 /
surplus 1,595,293.76.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>