Skip to content

Add flex-budget context to get_budgets (flex bucket + section totals)#77

Open
asreynolds1000 wants to merge 1 commit into
robcerda:mainfrom
asreynolds1000:feat/flex-budget-read
Open

Add flex-budget context to get_budgets (flex bucket + section totals)#77
asreynolds1000 wants to merge 1 commit into
robcerda:mainfrom
asreynolds1000:feat/flex-budget-read

Conversation

@asreynolds1000

Copy link
Copy Markdown
Contributor

What & why

Under Monarch's Fixed & Flexible budgeting mode, the real flexible budget is a single flex-bucket total (budgetData.monthlyAmountsForFlexExpense) that the individual flex category sub-budgets do not sum to. Today get_budgets only returns per-category planned/actual, so any analysis of flexible spending compares against sub-budgets that aren't the real budget — which is misleading (you can be "under" on every flex category while the flex bucket is blown).

Change

get_budgets now returns, alongside the existing category rows:

  • flex_bucket — per-month flex-bucket planned / actual / remaining.
  • section_totals — per-month Fixed / Non-Monthly / Flexible / total_expenses / income rollups, the way Monarch computes the budget (total budget = Fixed + Non-Monthly + Flex bucket).

Both come from fields on budgetData (monthlyAmountsForFlexExpense, totalsByMonth). They deliberately do not touch the guarded category-group fields (budgetVariability / rolloverPeriod) that some accounts reject — the existing compatibility guard and its test are preserved.

Return shape

Changes from a bare list to { "categories": [...], "flex_bucket": [...], "section_totals": [...] }. For category-based (non-flex) budgets, flex_bucket / section_totals come back empty and categories is unchanged.

Tests

  • Updated the return-shape and category-row tests.
  • Added unit tests for format_flex_bucket and format_section_totals.
  • Added a test asserting the query requests the flex fields (and the existing guard test still asserts no budgetVariability/rolloverPeriod).
  • Full suite: 226 passing.

Verified live against a Fixed & Flex account: the flex bucket and Fixed/Non-Monthly/Flexible section totals return correctly per month.

🤖 Generated with Claude Code

Under Monarch's "Fixed & Flexible" budgeting the real flexible budget is a
single flex-bucket total that the per-category flex sub-budgets do NOT sum to,
so the per-category planned amounts alone can't convey the actual flexible
budget. Analyzing flex categories against their sub-budgets is misleading.

get_budgets now also returns, alongside the existing category rows:
- flex_bucket: per-month flex-bucket planned/actual/remaining
  (budgetData.monthlyAmountsForFlexExpense)
- section_totals: per-month Fixed / Non-Monthly / Flexible / overall rollups
  the way Monarch computes the budget (budgetData.totalsByMonth)

Both fields live on budgetData and don't touch the guarded category-group
fields (budgetVariability/rolloverPeriod), so the existing account-compatibility
constraint is preserved. Return shape becomes
{categories, flex_bucket, section_totals}; docstring updated. Adds tests for
both new formatters and asserts the query requests the flex fields.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant