[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) <aab@odoo.com>
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
This commit is contained in:
Bruno Boi
2023-02-14 13:13:58 +01:00
committed by Mathieu Duckerts-Antoine
parent b0c7d888c5
commit b8b42d5a49
4 changed files with 53 additions and 0 deletions
@@ -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);
@@ -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();
@@ -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: `
<graph sample="1">
<field name="date"/>
</graph>
`,
});
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);
}
);
});
@@ -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: `
<pivot sample="1">
<field name="product_id" type="row"/>
</pivot>
`,
});
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");
}
);
});