From f266b761c2da8c65ed7e23a8f5a78e6b74e602c8 Mon Sep 17 00:00:00 2001 From: Pranay S Date: Sun, 15 Mar 2026 11:58:22 -0400 Subject: [PATCH] [AI] Fix Spending Analysis budget table for tracking budgeting (#7191) * [AI] Fix Spending Analysis budget table for tracking budgeting Made-with: Cursor * [autofix.ci] apply automated fixes * [AI] Add release note for Spending Analysis tracking budgeting fix Made-with: Cursor * [autofix.ci] apply automated fixes * [AI] Address CodeRabbit nitpicks: use typed narrowing instead of assertion for budgetType Made-with: Cursor --------- Co-authored-by: Pranay Mac M1 Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../src/components/reports/reports/Spending.tsx | 7 ++++++- .../src/components/reports/reports/SpendingCard.tsx | 7 ++++++- .../reports/spreadsheets/spending-spreadsheet.ts | 6 +++++- upcoming-release-notes/7191.md | 6 ++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 upcoming-release-notes/7191.md diff --git a/packages/desktop-client/src/components/reports/reports/Spending.tsx b/packages/desktop-client/src/components/reports/reports/Spending.tsx index a4acea58c7..94468ae263 100644 --- a/packages/desktop-client/src/components/reports/reports/Spending.tsx +++ b/packages/desktop-client/src/components/reports/reports/Spending.tsx @@ -46,6 +46,7 @@ import { useFormat } from '@desktop-client/hooks/useFormat'; import { useLocale } from '@desktop-client/hooks/useLocale'; import { useNavigate } from '@desktop-client/hooks/useNavigate'; import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters'; +import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref'; import { addNotification } from '@desktop-client/notifications/notificationsSlice'; import { useDispatch } from '@desktop-client/redux'; import { useUpdateDashboardWidgetMutation } from '@desktop-client/reports/mutations'; @@ -73,6 +74,9 @@ function SpendingInternal({ widget }: SpendingInternalProps) { const dispatch = useDispatch(); const { t } = useTranslation(); const format = useFormat(); + const [budgetTypePref] = useSyncedPref('budgetType'); + const budgetType: 'envelope' | 'tracking' = + budgetTypePref === 'tracking' ? 'tracking' : 'envelope'; const { conditions, @@ -145,8 +149,9 @@ function SpendingInternal({ widget }: SpendingInternalProps) { conditionsOp, compare, compareTo, + budgetType, }), - [conditions, conditionsOp, compare, compareTo], + [conditions, conditionsOp, compare, compareTo, budgetType], ); const data = useReport('default', getGraphData); diff --git a/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx b/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx index 0c30150f60..cc1db4fa44 100644 --- a/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx +++ b/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx @@ -21,6 +21,7 @@ import { createSpendingSpreadsheet } from '@desktop-client/components/reports/sp import { useDashboardWidgetCopyMenu } from '@desktop-client/components/reports/useDashboardWidgetCopyMenu'; import { useReport } from '@desktop-client/components/reports/useReport'; import { useFormat } from '@desktop-client/hooks/useFormat'; +import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref'; type SpendingCardProps = { widgetId: string; @@ -41,6 +42,9 @@ export function SpendingCard({ }: SpendingCardProps) { const { t } = useTranslation(); const format = useFormat(); + const [budgetTypePref] = useSyncedPref('budgetType'); + const budgetType: 'envelope' | 'tracking' = + budgetTypePref === 'tracking' ? 'tracking' : 'envelope'; const [isCardHovered, setIsCardHovered] = useState(false); const [nameMenuOpen, setNameMenuOpen] = useState(false); @@ -60,8 +64,9 @@ export function SpendingCard({ conditionsOp: meta?.conditionsOp, compare, compareTo, + budgetType, }); - }, [meta?.conditions, meta?.conditionsOp, compare, compareTo]); + }, [meta?.conditions, meta?.conditionsOp, compare, compareTo, budgetType]); const data = useReport('default', getGraphData); const todayDay = diff --git a/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts index 1e0a05eac1..2bf113a7a6 100644 --- a/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts +++ b/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts @@ -20,6 +20,7 @@ type createSpendingSpreadsheetProps = { conditionsOp?: string; compare?: string; compareTo?: string; + budgetType?: 'envelope' | 'tracking'; }; export function createSpendingSpreadsheet({ @@ -27,6 +28,7 @@ export function createSpendingSpreadsheet({ conditionsOp, compare, compareTo, + budgetType = 'envelope', }: createSpendingSpreadsheetProps) { const startDate = monthUtils.subMonths(compare, 3) + '-01'; const endDate = monthUtils.getMonthEnd(compare + '-01'); @@ -113,9 +115,11 @@ export function createSpendingSpreadsheet({ const combineDebts = [...debts, ...overlapDebts]; const budgetMonth = parseInt(compare.replace('-', '')); + const budgetTable = + budgetType === 'tracking' ? 'reflect_budgets' : 'zero_budgets'; const [budgets] = await Promise.all([ aqlQuery( - q('zero_budgets') + q(budgetTable) .filter({ $and: [{ month: { $eq: budgetMonth } }], }) diff --git a/upcoming-release-notes/7191.md b/upcoming-release-notes/7191.md new file mode 100644 index 0000000000..78550ea02c --- /dev/null +++ b/upcoming-release-notes/7191.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [pranayseela] +--- + +Fix Spending Analysis report to use tracking budgets when tracking budgeting is enabled