33 * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
44
55import { PivotModel } from "@web/views/pivot/pivot_model" ;
6+ import { _t } from "@web/core/l10n/translation" ;
67import { computeReportMeasures } from "@web/views/utils" ;
78import { evalOperation } from "../helpers/utils.esm" ;
89import { patch } from "@web/core/utils/patch" ;
@@ -144,10 +145,20 @@ patch(PivotModel.prototype, {
144145 _fillComputedMeasuresData ( subGroupData , config ) {
145146 for ( const cm of this . _computed_measures ) {
146147 if ( ! this . _isMeasureEnabled ( cm . id , config ) ) continue ;
148+ // _getMeasurements() later looks up this value as "<cm.id>:sum"
149+ // (our virtual field's aggregator, set in _createVirtualField),
150+ // so the computed result must be stored under that same key.
147151 if ( subGroupData . __count === 0 ) {
148- subGroupData [ cm . id ] = false ;
152+ subGroupData [ ` ${ cm . id } :sum` ] = false ;
149153 } else {
150- subGroupData [ cm . id ] = evalOperation ( cm . operation , subGroupData ) ;
154+ // Raw group values are keyed as "fieldName:aggregator" (e.g.
155+ // "partner_latitude:sum"), while cm.operation references bare
156+ // field names, so we need an unsuffixed lookup for evalOperation.
157+ const values = { } ;
158+ for ( const key in subGroupData ) {
159+ values [ key . split ( ":" ) [ 0 ] ] = subGroupData [ key ] ;
160+ }
161+ subGroupData [ `${ cm . id } :sum` ] = evalOperation ( cm . operation , values ) ;
151162 }
152163 }
153164 } ,
@@ -167,24 +178,24 @@ patch(PivotModel.prototype, {
167178 } ,
168179
169180 /**
170- * _getGroupSubdivision method invokes the read_group method of the
171- * model via rpc and the passed 'fields' argument is the list of
181+ * _getGroupsSubdivision method invokes the read_group method of the
182+ * model via rpc and the passed 'measureSpecs' param is the list of
172183 * measure names that is in this.metaData.activeMeasures, so we remove the
173- * computed measures form this.metaData.activeMeasures before calling _super
184+ * computed measures form params.measureSpecs before calling _super
174185 * to prevent any possible exception.
175186 *
176187 * @override
177188 */
178- async _getGroupSubdivision ( group , rowGroupBy , colGroupBy , config ) {
189+ async _getGroupsSubdivision ( params , groupInfo ) {
179190 const computed_measures = [ ] ;
180- for ( let i = 0 ; i < config . measureSpecs . length ; i ++ )
181- if ( config . measureSpecs [ i ] . startsWith ( "__computed_" ) ) {
182- computed_measures . push ( config . measureSpecs [ i ] ) ;
183- config . measureSpecs . splice ( i , 1 ) ;
191+ for ( let i = 0 ; i < params . measureSpecs . length ; i ++ )
192+ if ( params . measureSpecs [ i ] . startsWith ( "__computed_" ) ) {
193+ computed_measures . push ( params . measureSpecs [ i ] ) ;
194+ params . measureSpecs . splice ( i , 1 ) ;
184195 i -- ;
185196 }
186- const res = await super . _getGroupSubdivision ( ... arguments ) ;
187- Object . assign ( config . measureSpecs , computed_measures ) ;
197+ const res = await super . _getGroupsSubdivision ( params , groupInfo ) ;
198+ Object . assign ( params . measureSpecs , computed_measures ) ;
188199 return res ;
189200 } ,
190201
@@ -202,7 +213,7 @@ patch(PivotModel.prototype, {
202213 } ) ;
203214 if ( umeasures . length && this . _isMeasureEnabled ( umeasures [ 0 ] . id ) ) {
204215 return Promise . reject (
205- this . env . _t (
216+ _t (
206217 "This measure is currently used by a 'computed measure'. Please, disable the computed measure first."
207218 )
208219 ) ;
@@ -255,8 +266,7 @@ patch(PivotModel.prototype, {
255266 metaData . measures = computeReportMeasures (
256267 metaData . fields ,
257268 metaData . fieldAttrs ,
258- metaData . activeMeasures ,
259- metaData . additionalMeasures
269+ metaData . activeMeasures
260270 ) ;
261271 config = { metaData, data : this . data } ;
262272 }
0 commit comments