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

* [AI] Fix forecast all future range

* [AI] Add release note for balance forecast range fix
This commit is contained in:
Sebastián Maluk
2026-05-17 14:52:54 -04:00
committed by GitHub
parent 44f1aac59a
commit fee8fbccd1
4 changed files with 34 additions and 8 deletions

View File

@@ -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',
]);
});
});

View File

@@ -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;

View File

@@ -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}

View File

@@ -0,0 +1,6 @@
---
category: Bugfixes
authors: [samaluk]
---
Fix the Balance Forecast report's All future range.