From b8b42d5a49a8a3ccaf9f13a68510fd4af08fc182 Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Wed, 14 Dec 2022 10:17:33 +0000 Subject: [PATCH] [FIX] web: pivot,graph: usesamplemodel to false After a model in sample mode has fetched sample data, its orm is reset to be the "true" orm (standard orm service using the real server (prod) or the mock server (test)). Thus any change in the view parameters that imply to fetch data will lead to fetch "true" data (possibly none) and thus present "true" data in the view. The problem is that the graph and pivot views did keep the class .o_view_sample_data in that case. Here, we make sure that that class is removed at an appropriate time. closes odoo/odoo#112612 X-original-commit: ae6ec8dcfb24b86743e3ee14ae2526b4f8b681b9 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Mathieu Duckerts-Antoine --- .../web/static/src/views/graph/graph_model.js | 1 + .../web/static/src/views/pivot/pivot_model.js | 1 + .../static/tests/views/graph_view_tests.js | 26 +++++++++++++++++++ .../static/tests/views/pivot_view_tests.js | 25 ++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/addons/web/static/src/views/graph/graph_model.js b/addons/web/static/src/views/graph/graph_model.js index 30d7018f572..87df2bac813 100644 --- a/addons/web/static/src/views/graph/graph_model.js +++ b/addons/web/static/src/views/graph/graph_model.js @@ -132,6 +132,7 @@ export class GraphModel extends Model { if ("measure" in params) { const metaData = this._buildMetaData(params); await this._fetchDataPoints(metaData); + this.useSampleModel = false; } else { await this.race.getCurrentProm(); this.metaData = Object.assign({}, this.metaData, params); diff --git a/addons/web/static/src/views/pivot/pivot_model.js b/addons/web/static/src/views/pivot/pivot_model.js index 94e17f1fb44..367787b9108 100644 --- a/addons/web/static/src/views/pivot/pivot_model.js +++ b/addons/web/static/src/views/pivot/pivot_model.js @@ -753,6 +753,7 @@ export class PivotModel extends Model { metaData.activeMeasures.push(fieldName); const config = { metaData, data: this.data }; await this._loadData(config); + this.useSampleModel = false; } this.nextActiveMeasures = null; this.notify(); diff --git a/addons/web/static/tests/views/graph_view_tests.js b/addons/web/static/tests/views/graph_view_tests.js index 50b31b1f5ae..4c7130af549 100644 --- a/addons/web/static/tests/views/graph_view_tests.js +++ b/addons/web/static/tests/views/graph_view_tests.js @@ -4104,4 +4104,30 @@ QUnit.module("Views", (hooks) => { checkDatasets(assert, graph, ["data"], { data: [SampleServer.MAIN_RECORDSET_SIZE] }); } ); + + QUnit.test( + "no class 'o_view_sample_data' when real data are presented", + async function (assert) { + serverData.models.foo.records = []; + const graph = await makeView({ + serverData, + type: "graph", + resModel: "foo", + arch: ` + + + + `, + }); + assert.containsOnce(target, ".o_graph_view .o_view_sample_data"); + assert.ok(getChart(graph).data.datasets.length); + await selectMode(target, "line"); + assert.containsOnce(target, ".o_graph_view .o_view_sample_data"); + assert.ok(getChart(graph).data.datasets.length); + await toggleMenu(target, "Measures"); + await toggleMenuItem(target, "Revenue"); + assert.containsNone(target, ".o_graph_view .o_view_sample_data"); + assert.notOk(getChart(graph).data.datasets.length); + } + ); }); diff --git a/addons/web/static/tests/views/pivot_view_tests.js b/addons/web/static/tests/views/pivot_view_tests.js index 7581bc9bba9..e91d459b70f 100644 --- a/addons/web/static/tests/views/pivot_view_tests.js +++ b/addons/web/static/tests/views/pivot_view_tests.js @@ -5568,4 +5568,29 @@ QUnit.module("Views", (hooks) => { ); } ); + + QUnit.test( + "no class 'o_view_sample_data' when real data are presented", + async function (assert) { + serverData.models.partner.fields.foo.store = true; + serverData.models.partner.records = []; + await makeView({ + type: "pivot", + resModel: "partner", + serverData, + arch: ` + + + + `, + }); + + assert.containsOnce(target, ".o_pivot_view .o_view_sample_data"); + assert.containsOnce(target, ".o_pivot_view table"); + await toggleMenu(target, "Measures"); + await toggleMenuItem(target, "Foo"); + assert.containsNone(target, ".o_pivot_view .o_view_sample_data"); + assert.containsNone(target, ".o_pivot_view table"); + } + ); });