[IMP] spreadsheet: add YTD in period filters
This commit adds YTD (year to date) filter to global period filters in dashboard. YTD filter gets the data from Jan 1st of the current year to today (included). The unit of its offset is year. task 3215947 closes odoo/odoo#118466 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
This commit is contained in:
@@ -75,6 +75,12 @@ export function getRelativeDateDomain(now, offset, rangeType, fieldName, fieldTy
|
||||
let endDate = now.endOf("day");
|
||||
let startDate = endDate;
|
||||
switch (rangeType) {
|
||||
case "year_to_date": {
|
||||
const offsetParam = { years: offset };
|
||||
startDate = now.startOf("year").plus(offsetParam);
|
||||
endDate = now.endOf("day").plus(offsetParam);
|
||||
break;
|
||||
}
|
||||
case "last_week": {
|
||||
const offsetParam = { days: 7 * offset };
|
||||
endDate = endDate.plus(offsetParam);
|
||||
|
||||
@@ -19,6 +19,7 @@ export const MEASURE_STYLE = { fillColor: "#f2f2f2", textColor: "#756f6f" };
|
||||
export const UNTITLED_SPREADSHEET_NAME = _lt("Untitled spreadsheet");
|
||||
|
||||
export const RELATIVE_DATE_RANGE_TYPES = [
|
||||
{ type: "year_to_date", description: _lt("Year to Date") },
|
||||
{ type: "last_week", description: _lt("Last 7 Days") },
|
||||
{ type: "last_month", description: _lt("Last 30 Days") },
|
||||
{ type: "last_three_months", description: _lt("Last 90 Days") },
|
||||
|
||||
@@ -8,6 +8,12 @@ import {
|
||||
const { DateTime } = luxon;
|
||||
|
||||
QUnit.module("spreadsheet > Global filters helpers", {}, () => {
|
||||
QUnit.test("getRelativeDateDomain > year_to_date (year to date)", async function (assert) {
|
||||
const now = DateTime.fromISO("2022-05-16");
|
||||
const domain = getRelativeDateDomain(now, 0, "year_to_date", "field", "date");
|
||||
assertDateDomainEqual(assert, "field", "2022-01-01", "2022-05-16", domain);
|
||||
});
|
||||
|
||||
QUnit.test("getRelativeDateDomain > last_week (last 7 days)", async function (assert) {
|
||||
const now = DateTime.fromISO("2022-05-16");
|
||||
const domain = getRelativeDateDomain(now, 0, "last_week", "field", "date");
|
||||
@@ -108,6 +114,15 @@ QUnit.module("spreadsheet > Global filters helpers", {}, () => {
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"getRelativeDateDomain > with offset > year_to_date (year to date)",
|
||||
async function (assert) {
|
||||
const now = DateTime.fromISO("2022-05-16");
|
||||
const domain = getRelativeDateDomain(now, -1, "year_to_date", "field", "date");
|
||||
assertDateDomainEqual(assert, "field", "2021-01-01", "2021-05-16", domain);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"getRelativeDateDomain > with offset > last_week (last 7 days)",
|
||||
async function (assert) {
|
||||
|
||||
@@ -1287,6 +1287,10 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
|
||||
assert.equal(getDateDomainDurationInDays(computedDomain), 7);
|
||||
assertDateDomainEqual(assert, "date", "2022-05-10", "2022-05-16", computedDomain);
|
||||
|
||||
await setGlobalFilterValue(model, { id: "42", value: "year_to_date" });
|
||||
computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assertDateDomainEqual(assert, "date", "2022-01-01", "2022-05-16", computedDomain);
|
||||
|
||||
await setGlobalFilterValue(model, { id: "42", value: "last_month" });
|
||||
computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assert.equal(getDateDomainDurationInDays(computedDomain), 30);
|
||||
@@ -1334,6 +1338,10 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
|
||||
assert.equal(getDateDomainDurationInDays(computedDomain), 7);
|
||||
assertDateDomainEqual(assert, "date", "2022-05-03", "2022-05-09", computedDomain);
|
||||
|
||||
await setGlobalFilterValue(model, { id: "42", value: "year_to_date" });
|
||||
computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assertDateDomainEqual(assert, "date", "2021-01-01", "2021-05-16", computedDomain);
|
||||
|
||||
await setGlobalFilterValue(model, { id: "42", value: "last_month" });
|
||||
computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assert.equal(getDateDomainDurationInDays(computedDomain), 30);
|
||||
|
||||
Reference in New Issue
Block a user