From 89d5cc3b3db9e86adebb28d45a03fa64baaefc36 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Thu, 2 May 2019 13:25:18 +0000 Subject: [PATCH] [FIX] web: measure/groupby many2one variation in pivot view In case a many2one field (let us say 'foo') is used simultaneously as a groupby and a measure in the pivot view, the values returned by a read_group for that many2one are of the form [id, label] and the aggregated values (always 1) are missing in the read_group results (datapoints). Thus typically, a datapoint is of the form {'foo': [1, 'Bar'], '__count': 4, ...} and does not contain information on the 'foo:count_distinct' value (this is a read_group bug). As a consequence, a special processing of the read_group datapoints is done in the pivot model to handle that situation and the value for 'foo:count_distinct' is infered correctly to be 1. In the pivot comparison mode, datapoints comming from the period and the comparison period (data and comparisonData sets) are identified if they have same values for the groupby fields and the measure values become small objects containing information on the the measure values for data and for comparisonData and on the related variation. Thus {foo: [1, 'Bar'], __count: 4, ...} from data and {foo: [1, 'Bar'], __count: 3, ...} from comparisonData should become a single datapoint { foo: [1, 'Bar'], __count: { data: 4, comparisonData: 3, variation: { magnitude: +33 (%) } } fooAggregate: { data: 1, comparisonData: 1, variation: { magnitude: 0 (%) } } It turns out that the code responsible for merging the data and comparison datapoints made a mistake by mixing the keys 'foo' and 'fooAggregate', with the consequence that the variations were not correctly computed in the situation described above. This is fixed in this commit. closes odoo/odoo#33118 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/views/pivot/pivot_model.js | 4 ++-- addons/web/static/tests/views/pivot_tests.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js index 5758b906421..b60cf81ac86 100644 --- a/addons/web/static/src/js/views/pivot/pivot_model.js +++ b/addons/web/static/src/js/views/pivot/pivot_model.js @@ -950,8 +950,8 @@ var PivotModel = AbstractModel.extend({ } if (measureComparisonValue instanceof Array) { dataPoints[groupIdentifier][measureName + 'Aggregate'].comparisonData = 1; - dataPoints[groupIdentifier][measureName].variation = computeVariation( - dataPoints[groupIdentifier][measureName].data, + dataPoints[groupIdentifier][measureName + 'Aggregate'].variation = computeVariation( + dataPoints[groupIdentifier][measureName + 'Aggregate'].data, 1 ); diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 69c674479d1..be99c129cda 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -1639,7 +1639,7 @@ QUnit.module('Views', { results = [ "2", "0", "100%", "0", "1", "-100%", "2", "1", "100%" , "1", "0", "100%", "1", "0" , "100%" , - "1" , "0", "100%", "0", "1", "-100%", "1" , "1" , "100%" + "1" , "0", "100%", "0", "1", "-100%", "1" , "1" , "0%" ]; checkCellValues(results);