[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
This commit is contained in:
Lucas Lefèvre (lul)
2024-01-23 22:51:48 +00:00
parent fbfc5b2d5d
commit 33b910fcfd
3 changed files with 21 additions and 11 deletions
@@ -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
*/
@@ -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");
@@ -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);
}