Skip to content

[AI] Make BALANCE_OF available in formula reports - #8591

Merged
youngcw merged 3 commits into
masterfrom
ai/balance-of-query-mode
Aug 10, 2026
Merged

youngcw merged 3 commits into
masterfrom
ai/balance-of-query-mode

Conversation

@youngcw

@youngcw youngcw commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Description

Make the balance_of function work in the formula report

Made by Claude

Related issue(s)

Testing

Checklist

  • Release notes added (see link above)
  • No obvious regressions in affected areas
  • Self-review has been performed - I have read every line of this diff and can explain what each change does and why it is needed

Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 36 13.1 MB → 13.1 MB (+1.91 kB) +0.01%
loot-core 1 4.63 MB → 4.63 MB (+229 B) +0.00%
api 2 3.84 MB → 3.84 MB (+225 B) +0.01%
cli 1 8.02 MB 0%
crdt 1 11.16 kB 0%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
36 13.1 MB → 13.1 MB (+1.91 kB) +0.01%
Changeset
File Δ Size
src/components/reports/reports/FormulaCard.tsx 📈 +277 B (+10.53%) 2.57 kB → 2.84 kB
src/hooks/useFormulaExecution.ts 📈 +966 B (+6.87%) 13.72 kB → 14.67 kB
src/components/reports/reports/Formula.tsx 📈 +277 B (+2.37%) 11.42 kB → 11.69 kB
home/runner/work/actual/actual/packages/loot-core/src/shared/formulas/customFunctions.ts 📈 +225 B (+1.99%) 11.04 kB → 11.26 kB
src/components/formula/formulaCatalog.ts 📈 +137 B (+0.35%) 38.6 kB → 38.73 kB
locale/en.json 📈 +72 B (+0.03%) 236.36 kB → 236.43 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
static/js/ReportRouter.js 1.39 MB → 1.4 MB (+1.48 kB) +0.10%
static/js/useDateFormat.js 2.93 MB → 2.93 MB (+225 B) +0.01%
static/js/FormulaEditor.js 762.13 kB → 762.26 kB (+137 B) +0.02%
static/js/en.js 236.36 kB → 236.43 kB (+72 B) +0.03%

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
static/js/index.js 1.57 MB 0%
static/js/AppliedFilters.js 35.51 kB 0%
static/js/BackgroundImage.js 121.09 kB 0%
static/js/ManageRules.js 71.66 kB 0%
static/js/PayeeRuleCountLabel.js 11.74 kB 0%
static/js/ScheduleEditForm.js 76.54 kB 0%
static/js/SchedulesTable.js 171.15 kB 0%
static/js/TransactionEdit.js 219.94 kB 0%
static/js/TransactionList.js 79.22 kB 0%
static/js/Value.js 2.03 MB 0%
static/js/bootstrapHyperFormula.js 302 B 0%
static/js/ca.js 171.68 kB 0%
static/js/chart-theme.js 670.28 kB 0%
static/js/client.js 452.05 kB 0%
static/js/de.js 179.29 kB 0%
static/js/en-GB.js 11.1 kB 0%
static/js/es.js 165.11 kB 0%
static/js/fr.js 171.84 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.46 kB 0%
static/js/it.js 152.57 kB 0%
static/js/narrow.js 287.24 kB 0%
static/js/nb-NO.js 136.51 kB 0%
static/js/nl.js 152.45 kB 0%
static/js/pl.js 137.04 kB 0%
static/js/pt-BR.js 179.66 kB 0%
static/js/theme.js 31.1 kB 0%
static/js/uk.js 200.72 kB 0%
static/js/useFormatList.js 10.22 kB 0%
static/js/useTransactionBatchActions.js 11.03 kB 0%
static/js/wide.js 274.04 kB 0%
static/js/workbox-window.prod.es5.js 7.21 kB 0%
static/js/zh-Hans.js 107.54 kB 0%

loot-core

Total

Files count Total bundle size % Changed
1 4.63 MB → 4.63 MB (+229 B) +0.00%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/shared/formulas/customFunctions.ts 📈 +229 B (+1.96%) 11.4 kB → 11.62 kB
View detailed bundle breakdown

Added

Asset File Size % Changed
kcab.worker.BFDzVMpI.js 0 B → 4.63 MB (+4.63 MB) -

Removed

Asset File Size % Changed
kcab.worker.7rV9_5dh.js 4.63 MB → 0 B (-4.63 MB) -100%

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged
No assets were unchanged


api

Total

Files count Total bundle size % Changed
2 3.84 MB → 3.84 MB (+225 B) +0.01%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/shared/formulas/customFunctions.ts 📈 +225 B (+1.98%) 11.12 kB → 11.34 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
index.js 3.84 MB → 3.84 MB (+225 B) +0.01%

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
models.js 0 B 0%

cli

Total

Files count Total bundle size % Changed
1 8.02 MB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
cli.js 8.02 MB 0%

crdt

Total

Files count Total bundle size % Changed
1 11.16 kB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
index.js 11.16 kB 0%

@actual-github-bot actual-github-bot Bot changed the title [AI] Make BALANCE_OF available in query/report formulas [WIP] [AI] Make BALANCE_OF available in query/report formulas Jul 29, 2026
@netlify

netlify Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 4fdedbb
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget/deploys/6a77780d7f2ccc00084836c8
😎 Deploy Preview https://deploy-preview-8591.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for actualbudget-website ready!

Name Link
🔨 Latest commit 4fdedbb
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget-website/deploys/6a77780d7b17ae000892da8e
😎 Deploy Preview https://deploy-preview-8591.www.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@youngcw youngcw changed the title [WIP] [AI] Make BALANCE_OF available in query/report formulas [WIP] [AI] Make BALANCE_OF available in formula reports Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

BALANCE_OF now works in query/report formulas by resolving accounts from supplied account data and prefetching current balances from transaction sums. Formula reports and cards pass account context to execution, with updated tests, catalog metadata, documentation, and release notes.

Changes

BALANCE_OF query support

Layer / File(s) Summary
Catalog availability
packages/desktop-client/src/components/formula/formulaCatalog.ts, packages/desktop-client/src/components/formula/formulaCatalog.test.ts
BALANCE_OF is available in query and transaction modes, with updated descriptions and shared-mode assertions.
Balance prefetch execution
packages/loot-core/src/shared/formulas/customFunctions.ts, packages/loot-core/src/server/rules/customFunctions.test.ts, packages/desktop-client/src/hooks/useFormulaExecution.ts
Formula contexts track requested account keys, resolve balances through transaction sums, and convert results to display units.
Report integration and validation
packages/desktop-client/src/components/reports/reports/Formula.tsx, packages/desktop-client/src/components/reports/reports/FormulaCard.tsx, packages/desktop-client/src/hooks/useFormulaExecution.test.ts
Formula reports and cards pass filtered account data to execution; tests cover ID, exact-name, and missing-account behavior.
Documentation and release notes
packages/docs/docs/experimental/formulas.md, upcoming-release-notes/balance-of-in-formula-cards.md
Documentation and release notes describe query-mode BALANCE_OF behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FormulaCard
  participant useFormulaExecution
  participant CustomFunctionsPlugin
  participant TransactionsQuery
  FormulaCard->>useFormulaExecution: formula and simpleAccounts
  useFormulaExecution->>CustomFunctionsPlugin: evaluate BALANCE_OF(accountKey)
  CustomFunctionsPlugin->>useFormulaExecution: record account key and use prefetched balance
  useFormulaExecution->>TransactionsQuery: sum transaction amounts
  TransactionsQuery-->>useFormulaExecution: account balance
  useFormulaExecution-->>FormulaCard: formatted formula result
Loading

Suggested labels: documentation

Suggested reviewers: matt-fidd

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling BALANCE_OF in formula reports.
Description check ✅ Passed The description directly explains that the PR adds BALANCE_OF support to formula reports and includes related testing and release notes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ai/balance-of-query-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/desktop-client/src/hooks/useFormulaExecution.test.ts (1)

273-283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that name lookup resolves to the account ID.

This test accepts the mock’s constant response even if the emitted query filters on "Checking" instead of "acc1". Inspect the captured payload as the ID test does.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/desktop-client/src/hooks/useFormulaExecution.test.ts` around lines
273 - 283, Update the test using useFormulaExecution for exact-name account
resolution to inspect the captured query payload, following the existing
account-ID test pattern. Assert that the emitted lookup filters by the resolved
account ID "acc1", while preserving the existing result assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/desktop-client/src/components/formula/formulaCatalog.ts`:
- Around line 1007-1008: Update the description passed to t() in formulaCatalog
so the cents unit applies only to rule-formula balances, while explicitly
stating that report/query formula balances use money/display units. Preserve the
existing guidance about cutoff behavior and account matching.

In `@packages/docs/docs/experimental/formulas.md`:
- Line 102: Update the ISREF entry in the formula catalog table to list only
“Query” under supported modes, removing “Rules” while preserving the existing
description, example, and other metadata.

---

Nitpick comments:
In `@packages/desktop-client/src/hooks/useFormulaExecution.test.ts`:
- Around line 273-283: Update the test using useFormulaExecution for exact-name
account resolution to inspect the captured query payload, following the existing
account-ID test pattern. Assert that the emitted lookup filters by the resolved
account ID "acc1", while preserving the existing result assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cffe214a-2906-468b-bd43-d5bddf41ae6f

📥 Commits

Reviewing files that changed from the base of the PR and between 79f7860 and eab1905.

📒 Files selected for processing (10)
  • packages/desktop-client/src/components/formula/formulaCatalog.test.ts
  • packages/desktop-client/src/components/formula/formulaCatalog.ts
  • packages/desktop-client/src/components/reports/reports/Formula.tsx
  • packages/desktop-client/src/components/reports/reports/FormulaCard.tsx
  • packages/desktop-client/src/hooks/useFormulaExecution.test.ts
  • packages/desktop-client/src/hooks/useFormulaExecution.ts
  • packages/docs/docs/experimental/formulas.md
  • packages/loot-core/src/server/rules/customFunctions.test.ts
  • packages/loot-core/src/shared/formulas/customFunctions.ts
  • upcoming-release-notes/balance-of-in-formula-cards.md

@youngcw youngcw changed the title [WIP] [AI] Make BALANCE_OF available in formula reports [AI] Make BALANCE_OF available in formula reports Jul 31, 2026
@matt-fidd

Copy link
Copy Markdown
Member

Is it possible to add account name autocomplete?

@youngcw

youngcw commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

Is it possible to add account name autocomplete?

Probably, there already is category autocomplete, but I would rather that is its own PR.

@youngcw
youngcw added this pull request to the merge queue Aug 10, 2026
Merged via the queue into master with commit c4bc3e5 Aug 10, 2026
42 checks passed
@youngcw
youngcw deleted the ai/balance-of-query-mode branch August 10, 2026 16:43
youngcw added a commit that referenced this pull request Aug 13, 2026
Resolves conflicts with #8591, which added a fifth `accounts` argument to
`useFormulaExecution` for BALANCE_OF support.

- Give `accounts` the same treatment as `queries`/`namedExpressions`: key
  the effect on its serialized contents and read the live array through a
  ref, so a caller passing a fresh array each render can't restart the
  execution loop.
- Keep both new test suites (BALANCE_OF and execution stability), and
  extend the stability test to pass a fresh accounts array too.
- Replace `const { data: accounts = [] } = useAccounts()` in FormulaCard
  with a nullish coalesce onto a module-level constant. The destructuring
  default was re-triggering the same React Compiler bailout this PR
  removed from the props, which would have left the component unmemoized
  again.

Co-Authored-By: Claude Opus 5 <[email protected]>
sreetamdas added a commit to sreetamdas/actual that referenced this pull request Sep 2, 2026
RafaelEspino pushed a commit to RafaelEspino/actual that referenced this pull request Oct 28, 2026
* [AI] Make BALANCE_OF available in query/report formulas

* [AI] Address CodeRabbit review comments on BALANCE_OF PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants