[FIX] spreadsheet: format pivot days header
This commit fixes 2 very similar issue. See enterprise commit. - Group a pivot by any date field, with the day aggregate - insert it in spreadsheet - autofill a pivot function => the autofill tooltip displays the day number instead of the day formatted as a date. - on the same pivot - click on menu "Data > Insert pivot > insert pivot cell > [you pivot]" => in the dialog, numbers appears for the headers. Task: 3570281 Part-of: odoo/odoo#139295
This commit is contained in:
@@ -9,7 +9,8 @@ import { globalFiltersFieldMatchers } from "@spreadsheet/global_filters/plugins/
|
||||
import { PivotDataSource } from "../pivot_data_source";
|
||||
import { pivotTimeAdapter } from "../pivot_time_adapters";
|
||||
|
||||
const { astToFormula } = spreadsheet;
|
||||
const { astToFormula, helpers } = spreadsheet;
|
||||
const { formatValue } = helpers;
|
||||
const { DateTime } = luxon;
|
||||
|
||||
/**
|
||||
@@ -317,6 +318,23 @@ export class PivotUIPlugin extends spreadsheet.UIPlugin {
|
||||
return dataSource.computeOdooPivotHeaderValue(domainArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* High level method computing the formatted result of ODOO.PIVOT.HEADER functions.
|
||||
*
|
||||
* @param {string} pivotId
|
||||
* @param {(string | number)[]} pivotArgs arguments of the function (except the first one which is the pivot id)
|
||||
*/
|
||||
getPivotHeaderFormattedValue(pivotId, pivotArgs) {
|
||||
const dataSource = this.getters.getPivotDataSource(pivotId);
|
||||
const value = dataSource.computeOdooPivotHeaderValue(pivotArgs);
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
const format = this.getPivotFieldFormat(pivotId, pivotArgs.at(-2));
|
||||
const locale = this.getters.getLocale();
|
||||
return formatValue(value, { format, locale });
|
||||
}
|
||||
|
||||
getPivotFieldFormat(pivotId, fieldName) {
|
||||
const dataSource = this.getPivotDataSource(pivotId);
|
||||
const { field, aggregateOperator } = dataSource.parseGroupField(fieldName);
|
||||
@@ -547,6 +565,7 @@ PivotUIPlugin.getters = [
|
||||
"getSelectedPivotId",
|
||||
"getPivotComputedDomain",
|
||||
"computeOdooPivotHeaderValue",
|
||||
"getPivotHeaderFormattedValue",
|
||||
"getPivotFieldFormat",
|
||||
"getPivotIdFromPosition",
|
||||
"getPivotCellValue",
|
||||
|
||||
Reference in New Issue
Block a user