From d4c60f233ca5f9df570b4f9e19aa5eb9a96043e4 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Mon, 13 Feb 2023 14:24:03 +0000 Subject: [PATCH] [IMP] web: aggregate value for displayed columns The purpose of this commit is to no longer calculate the aggregated value of columns that are not displayed in the list view. Before this commit, we always calculated the aggregate value of optional columns that are hidden. closes odoo/odoo#112542 Signed-off-by: Aaron Bohy (aab) --- .../web/static/src/views/list/list_renderer.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index 3ec8c29b7ba..2bf7e1477c0 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -521,7 +521,14 @@ export class ListRenderer extends Component { values = this.props.list.records.map((r) => r.data); } const aggregates = {}; - for (const fieldName in this.props.list.activeFields) { + for (const column of this.allColumns) { + if (column.type !== "field") { + continue; + } + const fieldName = column.name; + if (fieldName in this.optionalActiveFields && !this.optionalActiveFields[fieldName]) { + continue; + } const field = this.fields[fieldName]; const fieldValues = values.map((v) => v[fieldName]).filter((v) => v || v === 0); if (!fieldValues.length) { @@ -531,7 +538,7 @@ export class ListRenderer extends Component { if (type !== "integer" && type !== "float" && type !== "monetary") { continue; } - const { rawAttrs, widget } = this.props.list.activeFields[fieldName]; + const { rawAttrs, widget } = column; const func = (rawAttrs.sum && "sum") || (rawAttrs.avg && "avg") || @@ -864,12 +871,13 @@ export class ListRenderer extends Component { getOptionalActiveFields() { this.optionalActiveFields = {}; const optionalActiveFields = browser.localStorage.getItem(this.keyOptionalFields); + const optionalColumns = this.allColumns.filter((col) => col.optional); if (optionalActiveFields) { - this.allColumns.forEach((col) => { + optionalColumns.forEach((col) => { this.optionalActiveFields[col.name] = optionalActiveFields.includes(col.name); }); } else { - this.allColumns.forEach((col) => { + optionalColumns.forEach((col) => { this.optionalActiveFields[col.name] = col.optional === "show"; }); }