[FIX] spreadsheet: correctly apply filter on chart in dashboard mode

Before this commit, a global filter did not update the domain of a chart
in dashboard mode.

Task-id 2961578

closes odoo/odoo#100047

Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
This commit is contained in:
Pierre Rousseau
2022-09-15 10:03:00 +02:00
parent 2971dc0a98
commit 7101ebb9f7
2 changed files with 29 additions and 1 deletions
@@ -4,7 +4,11 @@ import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
const { chartComponentRegistry } = spreadsheet.registries;
const { ChartJsComponent } = spreadsheet.components;
const { invalidateEvaluationCommands, readonlyAllowedCommands } = spreadsheet;
chartComponentRegistry.add("odoo_bar", ChartJsComponent);
chartComponentRegistry.add("odoo_line", ChartJsComponent);
chartComponentRegistry.add("odoo_pie", ChartJsComponent);
invalidateEvaluationCommands.add("ADD_GRAPH_DOMAIN");
readonlyAllowedCommands.add("ADD_GRAPH_DOMAIN");
@@ -1,7 +1,7 @@
/** @odoo-module */
import { createSpreadsheetWithGraph } from "../utils/chart";
import { addGlobalFilter } from "../utils/commands";
import { addGlobalFilter, setGlobalFilterValue } from "../utils/commands";
async function addChartGlobalFilter(model) {
const chartId = model.getters.getChartIds(model.getters.getActiveSheetId())[0];
@@ -42,4 +42,28 @@ QUnit.module("spreadsheet > Global filters chart", {}, () => {
});
await addChartGlobalFilter(model);
});
QUnit.test("Chart is impacted by global filter in dashboard mode", async function (assert) {
const { model } = await createSpreadsheetWithGraph();
assert.equal(model.getters.getGlobalFilters().length, 0);
const chartId = model.getters.getChartIds(model.getters.getActiveSheetId())[0];
const filter = {
id: "42",
type: "date",
label: "Last Year",
rangeType: "year",
graphFields: { [chartId]: { field: "date", type: "date" } },
};
await addGlobalFilter(model, { filter });
model.updateMode("dashboard");
let computedDomain = model.getters.getGraphDataSource(chartId).getComputedDomain();
assert.equal(computedDomain.length, 0);
await setGlobalFilterValue(model, {
id: "42",
value: { yearOffset: -1 },
});
computedDomain = model.getters.getGraphDataSource(chartId).getComputedDomain();
assert.equal(computedDomain.length, 3);
assert.equal(computedDomain[0], "&");
});
});