[FIX] spreadsheet: do not evaluate domain for date filters without a field

We were trying to evaluate the domain of a date filter when no chain was
provided in the field matching instead of returning an undefined domain
like for the other types of filters.

Task 3114332

closes odoo/odoo#110131

X-original-commit: 6eddb4b684d5c233b650f86fd8b26dcb8af4ca2d
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
This commit is contained in:
Rémi Rahir
2023-01-18 06:55:51 +01:00
parent d6dc5d0fbb
commit e10d00acfd
3 changed files with 21 additions and 11 deletions
@@ -3,7 +3,8 @@
/**
* @typedef {import("@spreadsheet/data_sources/metadata_repository").Field} Field
* @typedef {import("./global_filters_core_plugin").GlobalFilter} GlobalFilter
*
* @typedef {import("./global_filters_core_plugin").FieldMatching} FieldMatching
*/
import { _t } from "@web/core/l10n/translation";
@@ -324,14 +325,14 @@ export default class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin {
* @param {GlobalFilter} filter
* @param {FieldMatching} fieldMatching
*
* @returns {Domain|undefined}
* @returns {Domain}
*/
_getDateDomain(filter, fieldMatching) {
if (!this.isGlobalFilterActive(filter.id)) {
return undefined;
}
let granularity;
const value = this.getGlobalFilterValue(filter.id);
if (!value || !fieldMatching.chain) {
return new Domain();
}
const field = fieldMatching.chain;
const type = fieldMatching.type;
const offset = fieldMatching.offset || 0;
@@ -380,12 +381,12 @@ export default class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin {
* @param {GlobalFilter} filter
* @param {FieldMatching} fieldMatching
*
* @returns {Domain|undefined}
* @returns {Domain}
*/
_getTextDomain(filter, fieldMatching) {
const value = this.getGlobalFilterValue(filter.id);
if (!value || !fieldMatching.chain) {
return undefined;
return new Domain();
}
const field = fieldMatching.chain;
return new Domain([[field, "ilike", value]]);
@@ -399,12 +400,12 @@ export default class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin {
* @param {GlobalFilter} filter
* @param {FieldMatching} fieldMatching
*
* @returns {Domain|undefined}
* @returns {Domain}
*/
_getRelationDomain(filter, fieldMatching) {
const values = this.getGlobalFilterValue(filter.id);
if (!values || values.length === 0 || !fieldMatching.chain) {
return undefined;
return new Domain();
}
const field = fieldMatching.chain;
return new Domain([[field, "in", values]]);
@@ -63,7 +63,7 @@ QUnit.module("spreadsheet > Global filters chart", {}, () => {
);
model.updateMode("dashboard");
let computedDomain = model.getters.getChartDataSource(chartId).getComputedDomain();
assert.equal(computedDomain.length, 0);
assert.deepEqual(computedDomain, []);
await setGlobalFilterValue(model, {
id: "42",
value: { yearOffset: -1 },
@@ -93,6 +93,15 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
assert.equal(computedDomain[0], "&");
});
QUnit.test("Can add a global filter with an empty field matching (no field chain)", async function (assert) {
const { model } = await createSpreadsheetWithPivotAndList();
assert.equal(model.getters.getGlobalFilters().length, 0);
await addGlobalFilter(model, LAST_YEAR_FILTER, { pivot: {1: {}} });
assert.equal(model.getters.getGlobalFilters().length, 1);
const computedDomain = model.getters.getPivotComputedDomain("1");
assert.deepEqual(computedDomain, []);
});
QUnit.test("Can delete a global filter", async function (assert) {
assert.expect(4);
@@ -105,7 +114,7 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
assert.deepEqual(result, DispatchResult.Success);
assert.equal(model.getters.getGlobalFilters().length, 0);
const computedDomain = model.getters.getPivotComputedDomain("1");
assert.equal(computedDomain.length, 0);
assert.deepEqual(computedDomain, []);
});
QUnit.test("Can edit a global filter", async function (assert) {