[FIX] web: pivot: can toggle several measures at once
Before this commit, if the user quickly clicked on several measures (before the reload is over), only the last click was taken into account. With this commit, all changes are aggregated such that we only display the final result, with the desired measures. X-original-commit: a4bae57e1f3b095a4e2d35b3da424c34df59b8dd Part-of: odoo/odoo#76576
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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: `
|
||||
<pivot>
|
||||
<field name="foo" type="measure"/>
|
||||
<field name="product_id" type="row"/>
|
||||
</pivot>`,
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user