diff --git a/addons/web/static/src/views/pivot/pivot_model.js b/addons/web/static/src/views/pivot/pivot_model.js index 1a6723787a0..8af7fc813a5 100644 --- a/addons/web/static/src/views/pivot/pivot_model.js +++ b/addons/web/static/src/views/pivot/pivot_model.js @@ -379,6 +379,8 @@ export class PivotModel extends Model { domains: null, // not the same as searchParams.domains from cp origins: null, // generated from searchParams.domains from cp }; + + this.nextActiveMeasures = null; // allows to toggle several measures consecutively } //-------------------------------------------------------------------------- @@ -741,17 +743,21 @@ export class PivotModel extends Model { */ async toggleMeasure(fieldName) { const meta = this._buildMeta(); + this.nextActiveMeasures = this.nextActiveMeasures || meta.activeMeasures; + meta.activeMeasures = this.nextActiveMeasures; const index = meta.activeMeasures.indexOf(fieldName); if (index !== -1) { - this._cancelPreviousOperation(); // in this case, we already have all data in memory, no need to - // actually reload a lesser amount of information + // actually reload a lesser amount of information (but still, we need + // to wait in case there is a pending load) meta.activeMeasures.splice(index, 1); + await Promise.resolve(this.loadProm); } else { meta.activeMeasures.push(fieldName); const config = { meta, data: this.data, searchParams: this.searchParams }; this.data = await this._loadData(config); } + this.nextActiveMeasures = null; this.meta = meta; this.notify(); } diff --git a/addons/web/static/tests/views/pivot_view_tests.js b/addons/web/static/tests/views/pivot_view_tests.js index 3ddf7760f55..4839504cdf5 100644 --- a/addons/web/static/tests/views/pivot_view_tests.js +++ b/addons/web/static/tests/views/pivot_view_tests.js @@ -4845,6 +4845,43 @@ QUnit.module("Views", (hooks) => { assert.strictEqual(getCurrentValues(webClient), ["32", "12", "12", "20"].join(",")); }); + QUnit.test("consecutively toggle several measures", async function (assert) { + let def; + const pivot = await makeView({ + type: "pivot", + resModel: "partner", + serverData, + arch: ` + + + + `, + additionalMeasures: ["product_id"], + mockRPC(route, args) { + if (args.method === "read_group") { + return Promise.resolve(def); + } + }, + }); + + assert.strictEqual(getCurrentValues(pivot), ["32", "12", "20"].join(",")); + + // Toggle several measures (the reload is blocked, so all measures should be toggled in once) + def = makeDeferred(); + await toggleMenu(pivot, "Measures"); + await toggleMenuItem(pivot, "Product"); // add product + assert.strictEqual(getCurrentValues(pivot), ["32", "12", "20"].join(",")); + await toggleMenuItem(pivot, "Foo"); // remove foo + assert.strictEqual(getCurrentValues(pivot), ["32", "12", "20"].join(",")); + await toggleMenuItem(pivot, "Count"); // add count + assert.strictEqual(getCurrentValues(pivot), ["32", "12", "20"].join(",")); + + def.resolve(); + await nextTick(); + + assert.strictEqual(getCurrentValues(pivot), ["2", "4", "1", "1", "1", "3"].join(",")); + }); + QUnit.test( "if no measure is set in arch, 'Count' is used as measure initially", async function (assert) {