[FIX] spreadsheet: Empty value in date filter should bypass filter
A date filter with an empty value would still create a domain filtered on the current year instead of being bypassed. closes odoo/odoo#148984 Task: 3668916 X-original-commit: 763f88e2d45cb7ba107db135eecd0365ba2b8c8b Related: odoo/enterprise#54095 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com> Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
This commit is contained in:
@@ -436,7 +436,7 @@ export class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin {
|
||||
const noPeriod = !value.period || value.period === "empty";
|
||||
const noYear = value.yearOffset === undefined;
|
||||
if (noPeriod && noYear) {
|
||||
return [];
|
||||
return new Domain();
|
||||
}
|
||||
const setParam = { year: now.year };
|
||||
const yearOffset = value.yearOffset || 0;
|
||||
|
||||
@@ -251,18 +251,20 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
|
||||
const gf = model.getters.getGlobalFilters()[0];
|
||||
let result = await setGlobalFilterValue(model, {
|
||||
id: gf.id,
|
||||
value: { period: "february" },
|
||||
value: { period: "february", yearOffset: 0 },
|
||||
});
|
||||
assert.deepEqual(result, DispatchResult.Success);
|
||||
assert.equal(model.getters.getGlobalFilters().length, 1);
|
||||
assert.deepEqual(model.getters.getGlobalFilterDefaultValue(gf.id).yearOffset, -1);
|
||||
assert.deepEqual(model.getters.getGlobalFilterValue(gf.id).period, "february");
|
||||
assert.deepEqual(model.getters.getGlobalFilterValue(gf.id).yearOffset, 0);
|
||||
result = await setGlobalFilterValue(model, {
|
||||
id: gf.id,
|
||||
value: { period: "march" },
|
||||
value: { period: "march", yearOffset: 0 },
|
||||
});
|
||||
assert.deepEqual(result, DispatchResult.Success);
|
||||
assert.deepEqual(model.getters.getGlobalFilterValue(gf.id).period, "march");
|
||||
assert.deepEqual(model.getters.getGlobalFilterValue(gf.id).yearOffset, 0);
|
||||
const computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assert.equal(computedDomain.length, 3);
|
||||
const listDomain = model.getters.getListComputedDomain("1");
|
||||
@@ -1254,7 +1256,7 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
|
||||
type: "date",
|
||||
rangeType: "fixedPeriod",
|
||||
label: "This month",
|
||||
defaultValue: { yearOffset: 0, period: "january" },
|
||||
defaultValue: { period: "january", yearOffset: 0 },
|
||||
},
|
||||
pivot: {
|
||||
1: { chain: "date", type: "date" },
|
||||
@@ -1698,6 +1700,51 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("A date filter without a yearOffset value yields an empty domain", async function (assert) {
|
||||
patchDate(2022, 4, 16, 0, 0, 0);
|
||||
const { model } = await createSpreadsheetWithPivot();
|
||||
const filter = {
|
||||
id: "43",
|
||||
type: "date",
|
||||
label: "This Year",
|
||||
rangeType: "fixedPeriod",
|
||||
defaultValue: "this_year"
|
||||
};
|
||||
await addGlobalFilter(
|
||||
model,
|
||||
filter,
|
||||
{ pivot: { 1: { chain: "date", type: "date", offset: 0 } } }
|
||||
);
|
||||
let computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assertDateDomainEqual(assert, "date", "2022-01-01", "2022-12-31", computedDomain);
|
||||
model.dispatch("CLEAR_GLOBAL_FILTER_VALUE", { id: filter.id });
|
||||
computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assert.deepEqual(computedDomain, []);
|
||||
});
|
||||
|
||||
QUnit.test("Date filter with automatic default without a yearOffset value yields an empty domain", async function (assert) {
|
||||
patchDate(2022, 4, 16, 0, 0, 0);
|
||||
const { model } = await createSpreadsheetWithPivot();
|
||||
const filter = {
|
||||
id: "43",
|
||||
type: "date",
|
||||
label: "This Year",
|
||||
rangeType: "fixedPeriod",
|
||||
defaultValue: "this_year",
|
||||
defaultsToCurrentPeriod: true
|
||||
};
|
||||
await addGlobalFilter(
|
||||
model,
|
||||
filter,
|
||||
{ pivot: { 1: { chain: "date", type: "date", offset: 0 } } }
|
||||
);
|
||||
let computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assertDateDomainEqual(assert, "date", "2022-01-01", "2022-12-31", computedDomain);
|
||||
model.dispatch("CLEAR_GLOBAL_FILTER_VALUE", { id: filter.id });
|
||||
computedDomain = model.getters.getPivotComputedDomain("1");
|
||||
assert.deepEqual(computedDomain, []);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"Can set a value to a relation filter from the SET_MANY_GLOBAL_FILTER_VALUE command",
|
||||
async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user