[IMP] spreadsheet: Allow Odoo Chart domain edition
Task Description: This PR aims to add the possibility to edit the evaluation domain of an Odoo chart, the same way it can currently be done for other datasources like `List` or `Pivot`. This revision ensures that the chart datasources are properly reloaded their domain update. closes odoo/odoo#135242 Task: 3384872 Related: odoo/enterprise#47336 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
This commit is contained in:
committed by
Rémi Rahir (rar)
parent
bc15b92272
commit
5b29e2cd21
@@ -111,11 +111,13 @@ export default class OdooChartCorePlugin extends CorePlugin {
|
||||
* @returns {string}
|
||||
*/
|
||||
getOdooChartDisplayName(chartId) {
|
||||
return this.getters.getChart(chartId).title;
|
||||
return `(#${this.getOdooChartIds().indexOf(chartId) + 1}) ${
|
||||
this.getters.getChart(chartId).title
|
||||
}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the pivots
|
||||
* Import the charts
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
@@ -131,7 +133,7 @@ export default class OdooChartCorePlugin extends CorePlugin {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Export the pivots
|
||||
* Export the chart
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
@@ -154,7 +156,7 @@ export default class OdooChartCorePlugin extends CorePlugin {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the current pivotFieldMatching of a chart
|
||||
* Get the current odooChartFieldMatching of a chart
|
||||
*
|
||||
* @param {string} chartId
|
||||
* @param {string} filterId
|
||||
@@ -164,7 +166,7 @@ export default class OdooChartCorePlugin extends CorePlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current pivotFieldMatching of a chart
|
||||
* Sets the current odooChartFieldMatching of a chart
|
||||
*
|
||||
* @param {string} filterId
|
||||
* @param {Record<string,FieldMatching>} chartFieldMatches
|
||||
|
||||
@@ -60,9 +60,17 @@ export default class OdooChartUIPlugin extends UIPlugin {
|
||||
switch (cmd.definition.type) {
|
||||
case "odoo_pie":
|
||||
case "odoo_bar":
|
||||
case "odoo_line":
|
||||
case "odoo_line": {
|
||||
const dataSource = this.getChartDataSource(cmd.id);
|
||||
if (
|
||||
dataSource.getInitialDomainString() !==
|
||||
new Domain(cmd.definition.searchParams.domain).toString()
|
||||
) {
|
||||
this._resetChartDataSource(cmd.id);
|
||||
}
|
||||
this._setChartDataSource(cmd.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -74,7 +82,7 @@ export default class OdooChartUIPlugin extends UIPlugin {
|
||||
this._addDomains();
|
||||
break;
|
||||
case "UNDO":
|
||||
case "REDO":
|
||||
case "REDO": {
|
||||
if (
|
||||
cmd.commands.find((command) =>
|
||||
[
|
||||
@@ -86,6 +94,29 @@ export default class OdooChartUIPlugin extends UIPlugin {
|
||||
) {
|
||||
this._addDomains();
|
||||
}
|
||||
|
||||
const domainEditionCommands = cmd.commands.filter(
|
||||
(cmd) => cmd.type === "UPDATE_CHART" || cmd.type === "CREATE_CHART"
|
||||
);
|
||||
for (const cmd of domainEditionCommands) {
|
||||
if (!this.getters.getOdooChartIds().includes(cmd.id)) {
|
||||
continue;
|
||||
}
|
||||
const dataSource = this.getChartDataSource(cmd.id);
|
||||
if (
|
||||
dataSource.getInitialDomainString() !==
|
||||
new Domain(cmd.definition.searchParams.domain).toString()
|
||||
) {
|
||||
this._resetChartDataSource(cmd.id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "REFRESH_ODOO_CHART":
|
||||
this._refreshOdooChart(cmd.chartId);
|
||||
break;
|
||||
case "REFRESH_ALL_DATA_SOURCES":
|
||||
this._refreshOdooCharts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +149,7 @@ export default class OdooChartUIPlugin extends UIPlugin {
|
||||
domainList.push(this.getters.getGlobalFilterDomain(filterId, fieldMatch));
|
||||
}
|
||||
const domain = Domain.combine(domainList, "AND").toString();
|
||||
this.getters.getChartDataSource(chartId).addDomain(domain);
|
||||
this.getChartDataSource(chartId).addDomain(domain);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,15 +170,24 @@ export default class OdooChartUIPlugin extends UIPlugin {
|
||||
*/
|
||||
_setupChartDataSource(chartId) {
|
||||
const dataSourceId = this._getOdooChartDataSourceId(chartId);
|
||||
const definition = this.getters.getChart(chartId).getDefinitionForDataSource();
|
||||
if (!this.dataSources.contains(dataSourceId)) {
|
||||
this.dataSources.add(dataSourceId, ChartDataSource, definition);
|
||||
this._resetChartDataSource(chartId);
|
||||
}
|
||||
this._setChartDataSource(chartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the catasource on the corresponding chart
|
||||
* Sets the datasource on the corresponding chart
|
||||
* @param {string} chartId
|
||||
*/
|
||||
_resetChartDataSource(chartId) {
|
||||
const definition = this.getters.getChart(chartId).getDefinitionForDataSource();
|
||||
const dataSourceId = this._getOdooChartDataSourceId(chartId);
|
||||
this.dataSources.add(dataSourceId, ChartDataSource, definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the datasource on the corresponding chart
|
||||
* @param {string} chartId
|
||||
*/
|
||||
_setChartDataSource(chartId) {
|
||||
@@ -168,6 +208,23 @@ export default class OdooChartUIPlugin extends UIPlugin {
|
||||
_getOdooChartDataSourceId(chartId) {
|
||||
return `chart-${chartId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cache of a chart
|
||||
* @param {string} chartId Id of the chart
|
||||
*/
|
||||
_refreshOdooChart(chartId) {
|
||||
this.getChartDataSource(chartId).load({ reload: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cache of all the charts
|
||||
*/
|
||||
_refreshOdooCharts() {
|
||||
for (const chartId of this.getters.getOdooChartIds()) {
|
||||
this._refreshOdooChart(chartId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OdooChartUIPlugin.getters = ["getChartDataSource"];
|
||||
|
||||
@@ -97,6 +97,14 @@ export class OdooViewsDataSource extends LoadableDataSource {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current domain as a string
|
||||
* @returns { string }
|
||||
*/
|
||||
getInitialDomainString() {
|
||||
return new Domain(this._initialSearchParams.domain).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} domain
|
||||
|
||||
@@ -410,11 +410,10 @@ export default class PivotUIPlugin extends spreadsheet.UIPlugin {
|
||||
|
||||
/**
|
||||
* @param {string} pisvotId
|
||||
* @param {PivotDefinition=} definition
|
||||
*/
|
||||
_setupPivotDataSource(pivotId, definition) {
|
||||
_setupPivotDataSource(pivotId) {
|
||||
const dataSourceId = this.getPivotDataSourceId(pivotId);
|
||||
definition = definition || this.getters.getPivotModelDefinition(pivotId);
|
||||
const definition = this.getters.getPivotModelDefinition(pivotId);
|
||||
if (!this.dataSources.contains(dataSourceId)) {
|
||||
this.dataSources.add(dataSourceId, PivotDataSource, definition);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ QUnit.module("spreadsheet > odoo chart plugin", {}, () => {
|
||||
assert.verifySteps(["web_read_group"], "it should have loaded the data");
|
||||
});
|
||||
|
||||
QUnit.test("Changing the chart type does not reload the data", async (assert) => {
|
||||
QUnit.test("Data reloaded strictly upon domain update", async (assert) => {
|
||||
const { model } = await createSpreadsheetWithChart({
|
||||
type: "odoo_line",
|
||||
mockRPC: async function (route, args) {
|
||||
@@ -164,20 +164,37 @@ QUnit.module("spreadsheet > odoo chart plugin", {}, () => {
|
||||
// force runtime computation
|
||||
model.getters.getChartRuntime(chartId);
|
||||
await nextTick();
|
||||
|
||||
assert.verifySteps(["web_read_group"], "it should have loaded the data");
|
||||
|
||||
model.dispatch("UPDATE_CHART", {
|
||||
definition: {
|
||||
...definition,
|
||||
searchParams: { ...definition.searchParams, domain: [["1", "=", "1"]] },
|
||||
},
|
||||
id: chartId,
|
||||
sheetId,
|
||||
});
|
||||
// force runtime computation
|
||||
model.getters.getChartRuntime(chartId);
|
||||
await nextTick();
|
||||
assert.verifySteps(["web_read_group"], "it should have loaded the data with a new domain");
|
||||
|
||||
const newDefinition = model.getters.getChartDefinition(chartId);
|
||||
model.dispatch("UPDATE_CHART", {
|
||||
definition: {
|
||||
...newDefinition,
|
||||
type: "odoo_bar",
|
||||
},
|
||||
id: chartId,
|
||||
sheetId,
|
||||
});
|
||||
await nextTick();
|
||||
// force runtime computation
|
||||
model.getters.getChartRuntime(chartId);
|
||||
assert.verifySteps([], "it should have not have loaded the data a second time");
|
||||
await nextTick();
|
||||
assert.verifySteps(
|
||||
[],
|
||||
"it should have not have loaded the data since the domain was unchanged"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Can import/export an Odoo chart", async (assert) => {
|
||||
|
||||
Reference in New Issue
Block a user