[FIX] web: missing pivot measures when using favorites

Steps to reproduce
==================

- Go to budget analysis
- Switch to the pivot view
- Unselect the first three measures
- Save the current search and set it as default
- In the measures dropdown, there is only two measures remaining

Cause of the issue
==================

- When `context.pivot_measures` is used, the measures are computed from
  it and those that comes from the metaData are missing.

opw-3544823

closes odoo/odoo#139315

X-original-commit: b11266cc377fa4753a0ee609258d9919f1ba5496
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
Hubert Van de Walle (huvw)
2023-10-20 18:06:41 +00:00
parent 74497136cc
commit a026a9e9b1
2 changed files with 42 additions and 8 deletions
@@ -702,9 +702,8 @@ export class PivotModel extends Model {
*/
async load(searchParams) {
this.searchParams = searchParams;
const activeMeasures =
processMeasure(searchParams.context.pivot_measures) || this.metaData.activeMeasures;
const processedMeasures = processMeasure(searchParams.context.pivot_measures);
const activeMeasures = processedMeasures || this.metaData.activeMeasures;
const metaData = this._buildMetaData({ activeMeasures });
if (!this.reload) {
metaData.rowGroupBys =
@@ -726,11 +725,14 @@ export class PivotModel extends Model {
metaData.expandedColGroupBys = [];
}
metaData.measures = computeReportMeasures(
metaData.fields,
metaData.fieldAttrs,
metaData.activeMeasures
);
const allActivesMeasures = new Set(this.metaData.activeMeasures);
if (processedMeasures) {
processedMeasures.forEach((e) => allActivesMeasures.add(e));
}
metaData.measures = computeReportMeasures(metaData.fields, metaData.fieldAttrs, [
...allActivesMeasures,
]);
const config = { metaData, data: this.data };
return this._loadData(config);
}
@@ -285,6 +285,38 @@ QUnit.module("Views", (hooks) => {
);
});
QUnit.test(
"all measures should be displayed with a pivot_measures context",
async function (assert) {
assert.expect(1);
serverData.models.partner.fields.bouh = {
string: "bouh",
type: "integer",
group_operator: "sum",
};
await makeView({
type: "pivot",
resModel: "partner",
serverData,
context: { pivot_measures: ["foo"] },
arch: `
<pivot string="Partners">
<field name="foo" type="measure"/>
<field name="bouh" type="measure"/>
</pivot>`,
});
await click(target.querySelector(".o_pivot_buttons button.dropdown-toggle"));
const measures = Array.from(
target.querySelectorAll(".o_pivot_buttons .dropdown-menu .dropdown-item")
).map((e) => e.textContent);
assert.deepEqual(measures, ["bouh", "Foo", "Count"]);
}
);
QUnit.test("pivot rendering with widget", async function (assert) {
await makeView({
type: "pivot",