Skip to content

A local-first personal finance app

[AI] Fix balance forecast all future range (#7849)

Sebastián Malukfee8fbccd128
diff --git a/packages/desktop-client/src/components/reports/reportRanges.test.ts b/packages/desktop-client/src/components/reports/reportRanges.test.ts
index 91ab128e67..2edd86e769 100644
--- a/packages/desktop-client/src/components/reports/reportRanges.test.ts
+++ b/packages/desktop-client/src/components/reports/reportRanges.test.ts
@@ -1,8 +1,10 @@
+import * as monthUtils from '@actual-app/core/shared/months';
import { describe, expect, it } from 'vitest';
import {
calculateSpendingReportTimeRange,
calculateTimeRange,
+ getFullFutureRange,
} from './reportRanges';
// In test mode, monthUtils.currentMonth() returns '2017-01'
@@ -66,3 +68,26 @@ describe('calculateSpendingReportTimeRange', () => {
expect(compareTo).toBe('2017-01');
});
});
+
+describe('getFullFutureRange', () => {
+ it('uses a future month as the end of the range', () => {
+ const start = monthUtils.currentMonth();
+ const futureMonth = monthUtils.addMonths(start, 36);
+
+ expect(getFullFutureRange(futureMonth)).toEqual([
+ start,
+ futureMonth,
+ 'static',
+ ]);
+ });
+
+ it('falls back to a default future horizon without a future month', () => {
+ const start = monthUtils.currentMonth();
+
+ expect(getFullFutureRange()).toEqual([
+ start,
+ monthUtils.addMonths(start, 24),
+ 'static',
+ ]);
+ });
+});
diff --git a/packages/desktop-client/src/components/reports/reportRanges.ts b/packages/desktop-client/src/components/reports/reportRanges.ts
index d0ecd631ac..895f192199 100644
--- a/packages/desktop-client/src/components/reports/reportRanges.ts
+++ b/packages/desktop-client/src/components/reports/reportRanges.ts
@@ -184,12 +184,9 @@ export function getNextRange(offset: number) {
export function getFullFutureRange(latestMonth?: string) {
const start = monthUtils.currentMonth();
const defaultEnd = monthUtils.addMonths(start, 24);
- const latestMonthValue = latestMonth
- ? monthUtils.monthFromDate(latestMonth)
- : undefined;
const end =
- latestMonthValue && monthUtils.isAfter(latestMonthValue, start)
- ? latestMonthValue
+ latestMonth && monthUtils.isAfter(latestMonth, start)
+ ? latestMonth
: defaultEnd;
return [start, end, 'static'] as const;
diff --git a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
index 78c8cec302..f33cd3522a 100644
--- a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
@@ -301,9 +301,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
end={end}
earliestTransaction={earliestTransaction}
latestTransaction={
- forecastData?.forecastEndDate
- ? monthUtils.monthFromDate(forecastData.forecastEndDate)
- : (allMonths[0]?.name ?? monthUtils.addMonths(currentMonth, 24))
+ allMonths[0]?.name ?? monthUtils.addMonths(currentMonth, 24)
}
mode={mode}
onChangeDates={onChangeDates}
diff --git a/upcoming-release-notes/7849.md b/upcoming-release-notes/7849.md
new file mode 100644
index 0000000000..9f3f76b61a
--- /dev/null
+++ b/upcoming-release-notes/7849.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [samaluk]
+---
+
+Fix the Balance Forecast report's All future range.