mirror of
https://github.com/frappe/books.git
synced 2024-11-09 15:20:56 +00:00
fix(reports): correct date calculation in AccountReport
fyo.getValue(*, 'fiscalYear{Start,End}') returns a javascript Date object that encodes the filcal year as local time (01-01 and 12-31 at midnight). This date must not be converted to UTC else east timezones will return the day before (12-31 and 12-30). Use locale time values instead. When computing the monthly/quaterly/half yearly time periods, correct the dates in the particular case where the last day of the month is selected as reference date (yields series 12-31 11-30 10-31 09-30 ...) instead of (12-31 11-30 10-30 09-30 ...).
This commit is contained in:
parent
82a2c5e5b6
commit
d04b1561cd
@ -236,6 +236,17 @@ export abstract class AccountReport extends LedgerReport {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix arythmetic on dates when adding or substracting months. If the
|
||||||
|
// reference date was the last day in month, ensure that the resulting date is
|
||||||
|
// also the last day.
|
||||||
|
_fixMonthsJump(refDate: DateTime, date: DateTime): DateTime {
|
||||||
|
if (refDate.day == refDate.daysInMonth && date.day != date.daysInMonth) {
|
||||||
|
return date.set({day: date.daysInMonth})
|
||||||
|
} else {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _getDateRanges(): Promise<DateRange[]> {
|
async _getDateRanges(): Promise<DateRange[]> {
|
||||||
const endpoints = await this._getFromAndToDates();
|
const endpoints = await this._getFromAndToDates();
|
||||||
const fromDate = DateTime.fromISO(endpoints.fromDate);
|
const fromDate = DateTime.fromISO(endpoints.fromDate);
|
||||||
@ -252,7 +263,7 @@ export abstract class AccountReport extends LedgerReport {
|
|||||||
|
|
||||||
const months: number = monthsMap[this.periodicity];
|
const months: number = monthsMap[this.periodicity];
|
||||||
const dateRanges: DateRange[] = [
|
const dateRanges: DateRange[] = [
|
||||||
{ toDate, fromDate: toDate.minus({ months }) },
|
{ toDate, fromDate: this._fixMonthsJump(toDate, toDate.minus({ months })) },
|
||||||
];
|
];
|
||||||
|
|
||||||
let count = this.count ?? 1;
|
let count = this.count ?? 1;
|
||||||
@ -264,7 +275,7 @@ export abstract class AccountReport extends LedgerReport {
|
|||||||
const lastRange = dateRanges.at(-1)!;
|
const lastRange = dateRanges.at(-1)!;
|
||||||
dateRanges.push({
|
dateRanges.push({
|
||||||
toDate: lastRange.fromDate,
|
toDate: lastRange.fromDate,
|
||||||
fromDate: lastRange.fromDate.minus({ months }),
|
fromDate: this._fixMonthsJump(toDate, lastRange.fromDate.minus({ months })),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,14 +456,15 @@ export async function getFiscalEndpoints(
|
|||||||
|
|
||||||
const fromDate = [
|
const fromDate = [
|
||||||
fromYear,
|
fromYear,
|
||||||
fys.toISOString().split('T')[0].split('-').slice(1),
|
(fys.getMonth() + 1).toString().padStart(2, '0'),
|
||||||
]
|
fys.getDate().toString().padStart(2, '0')
|
||||||
.flat()
|
].join('-');
|
||||||
.join('-');
|
|
||||||
|
|
||||||
const toDate = [toYear, fye.toISOString().split('T')[0].split('-').slice(1)]
|
const toDate = [
|
||||||
.flat()
|
toYear,
|
||||||
.join('-');
|
(fye.getMonth() + 1).toString().padStart(2, '0'),
|
||||||
|
fye.getDate().toString().padStart(2, '0')
|
||||||
|
].join('-');
|
||||||
|
|
||||||
return { fromDate, toDate };
|
return { fromDate, toDate };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user