From f61c3870dc8921173d8c056eb010dd79fd5b8a5d Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 11 Apr 2023 07:05:59 +0000 Subject: [PATCH] [REF] web: move computeVariation in pivot_model Since the dashboard view has been removed, there was only one call to computeVariation of utils/numbers. We move the definition of that function where it is used (pivot_model.js). Part-of: odoo/odoo#118057 --- addons/web/static/src/core/utils/numbers.js | 21 ------------ .../web/static/src/views/pivot/pivot_model.js | 34 ++++++++++++++----- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/addons/web/static/src/core/utils/numbers.js b/addons/web/static/src/core/utils/numbers.js index b5f4f2cb4c5..54b0405492a 100644 --- a/addons/web/static/src/core/utils/numbers.js +++ b/addons/web/static/src/core/utils/numbers.js @@ -1,26 +1,5 @@ /** @odoo-module **/ -/** - * @param {number} value - * @param {number} comparisonValue - * @returns {number} - */ -export function computeVariation(value, comparisonValue) { - if (isNaN(value) || isNaN(comparisonValue)) { - return NaN; - } - if (comparisonValue === 0) { - if (value === 0) { - return 0; - } else if (value > 0) { - return 1; - } else { - return -1; - } - } - return (value - comparisonValue) / Math.abs(comparisonValue); -} - /** * Returns value clamped to the inclusive range of min and max. * diff --git a/addons/web/static/src/views/pivot/pivot_model.js b/addons/web/static/src/views/pivot/pivot_model.js index 367787b9108..b833589624b 100644 --- a/addons/web/static/src/views/pivot/pivot_model.js +++ b/addons/web/static/src/views/pivot/pivot_model.js @@ -3,11 +3,31 @@ import { Domain } from "@web/core/domain"; import { cartesian, sections, sortBy, symmetricalDifference } from "@web/core/utils/arrays"; import { KeepLast, Race } from "@web/core/utils/concurrency"; -import { computeVariation } from "@web/core/utils/numbers"; import { DEFAULT_INTERVAL } from "@web/search/utils/dates"; import { Model } from "@web/views/model"; import { computeReportMeasures, processMeasure } from "@web/views/utils"; +/** + * @param {number} value + * @param {number} comparisonValue + * @returns {number} + */ +function computeVariation(value, comparisonValue) { + if (isNaN(value) || isNaN(comparisonValue)) { + return NaN; + } + if (comparisonValue === 0) { + if (value === 0) { + return 0; + } else if (value > 0) { + return 1; + } else { + return -1; + } + } + return (value - comparisonValue) / Math.abs(comparisonValue); +} + /** * Pivot Model * @@ -1221,10 +1241,7 @@ export class PivotModel extends Model { rowIndex === 0 ? undefined : fields[colGroupBys[rowIndex - 1].split(":")[0]].string, - title: - group.labels.length - ? group.labels[group.labels.length - 1] - : _t("Total"), + title: group.labels.length ? group.labels[group.labels.length - 1] : _t("Total"), width: leafCount * measureCount * (2 * originCount - 1), }; row.push(cell); @@ -1275,10 +1292,9 @@ export class PivotModel extends Model { let rows = []; const group = tree.root; const rowGroupId = [group.values, []]; - const title = - group.labels.length - ? group.labels[group.labels.length - 1] - : this.env._t("Total"); + const title = group.labels.length + ? group.labels[group.labels.length - 1] + : this.env._t("Total"); const indent = group.labels.length; const isLeaf = !tree.directSubTrees.size; const rowGroupBys = this.metaData.fullRowGroupBys;