From 33b910fcfd69ec355f876fbc5b230d3a367fa324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Tue, 17 Oct 2023 18:24:42 +0200 Subject: [PATCH] [REF] spreadsheet: colocate special args in one place For the ODOO.PIVOT.HEADER functions, "special" values such as measure and total were managed in different places (total management was also duplicated see enterprise commit). Now the measure and total are managed in one place, in the high level method. There's also now a dedicated method to get a measure display name. The method `getGroupByDisplayLabel` was perverted at that purpose (see enterprise commit) Task: 3570281 Part-of: odoo/odoo#139295 --- .../static/src/pivot/pivot_data_source.js | 21 +++++++++++++++++++ .../static/src/pivot/pivot_model.js | 7 ------- .../src/pivot/plugins/pivot_ui_plugin.js | 4 ---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/addons/spreadsheet/static/src/pivot/pivot_data_source.js b/addons/spreadsheet/static/src/pivot/pivot_data_source.js index 2e7c09b7933..ecefccb70c5 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_data_source.js +++ b/addons/spreadsheet/static/src/pivot/pivot_data_source.js @@ -71,12 +71,33 @@ export class PivotDataSource extends OdooViewsDataSource { */ computeOdooPivotHeaderValue(domainArgs) { this._assertDataIsLoaded(); + if (domainArgs.length === 0) { + return _t("Total"); + } + if (domainArgs.at(-2) === "measure") { + return this.getMeasureDisplayName(domainArgs.at(-1)); + } return this._model.getGroupByDisplayLabel( domainArgs.at(-2), this._model.getLastPivotGroupValue(domainArgs) ); } + /** + * @param {string} measure + * @returns {string} + */ + getMeasureDisplayName(measure) { + if (measure === "__count") { + return _t("Count"); + } + const field = this.getField(measure); + if (field === undefined) { + throw new Error(_t("Field %s does not exist", measure)); + } + return field.string; + } + /** * @param {(string | number)[]} domainArgs */ diff --git a/addons/spreadsheet/static/src/pivot/pivot_model.js b/addons/spreadsheet/static/src/pivot/pivot_model.js index 2f24d148394..6f6ff6363d1 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_model.js +++ b/addons/spreadsheet/static/src/pivot/pivot_model.js @@ -303,13 +303,6 @@ export class SpreadsheetPivotModel extends PivotModel { if (groupValueString === NO_RECORD_AT_THIS_POSITION) { return ""; } - if (groupFieldString === "measure") { - if (groupValueString === "__count") { - return _t("Count"); - } - // the value is actually the measure field name - return this.parseGroupField(groupValueString).field.string; - } const { field, aggregateOperator } = this.parseGroupField(groupFieldString); const value = toNormalizedPivotValue(field, groupValueString, aggregateOperator); const undef = _t("None"); diff --git a/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js b/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js index 757fe0e1339..1f2824eb2bb 100644 --- a/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js +++ b/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js @@ -1,6 +1,5 @@ /** @odoo-module */ -import { _t } from "@web/core/l10n/translation"; import * as spreadsheet from "@odoo/o-spreadsheet"; import { getFirstPivotFunction, getNumberOfPivotFormulas } from "../pivot_helpers"; import { FILTER_DATE_OPTION, monthsOptions } from "@spreadsheet/assets_backend/constants"; @@ -314,9 +313,6 @@ export class PivotUIPlugin extends spreadsheet.UIPlugin { computeOdooPivotHeaderValue(pivotId, domainArgs) { const dataSource = this.getters.getPivotDataSource(pivotId); dataSource.markAsHeaderUsed(domainArgs); - if (domainArgs.length === 0) { - return _t("Total"); - } return dataSource.computeOdooPivotHeaderValue(domainArgs); }