Skip to content

Commit e8fa916

Browse files
committed
[MIG] web_pivot_computed_measure: Migration to 19.0
1 parent c32b7f2 commit e8fa916

6 files changed

Lines changed: 65 additions & 34 deletions

File tree

web_pivot_computed_measure/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Web Pivot Computed Measure
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
24-
:target: https://github.com/OCA/web/tree/18.0/web_pivot_computed_measure
24+
:target: https://github.com/OCA/web/tree/19.0/web_pivot_computed_measure
2525
:alt: OCA/web
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_pivot_computed_measure
27+
:target: https://translation.odoo-community.org/projects/web-19-0/web-19-0-web_pivot_computed_measure
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -91,7 +91,7 @@ Bug Tracker
9191
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
9292
In case of trouble, please check there if your issue has already been reported.
9393
If you spotted it first, help us to smash it by providing a detailed and welcomed
94-
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_pivot_computed_measure%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
94+
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_pivot_computed_measure%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
9595

9696
Do not contact contributors directly about support or help with technical issues.
9797

@@ -134,6 +134,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
134134

135135
|maintainer-CarlosRoca13|
136136

137-
This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_pivot_computed_measure>`_ project on GitHub.
137+
This module is part of the `OCA/web <https://github.com/OCA/web/tree/19.0/web_pivot_computed_measure>`_ project on GitHub.
138138

139139
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

web_pivot_computed_measure/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Web Pivot Computed Measure",
55
"category": "web",
6-
"version": "18.0.1.0.5",
6+
"version": "19.0.1.0.0",
77
"author": "Tecnativa, Odoo Community Association (OCA)",
88
"license": "AGPL-3",
99
"website": "https://github.com/OCA/web",

web_pivot_computed_measure/static/description/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Web Pivot Computed Measure</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:ab3cd4b5fcebcf88ffc1c122a3d7d2708d6e1d2ffad1cd33c62b9e688733a5d0
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_pivot_computed_measure"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_pivot_computed_measure"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/19.0/web_pivot_computed_measure"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-19-0/web-19-0-web_pivot_computed_measure"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>Adds support for computed measures on the pivot view.</p>
379379
<p><strong>Table of contents</strong></p>
380380
<div class="contents local topic" id="contents">
@@ -444,7 +444,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
444444
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
445445
In case of trouble, please check there if your issue has already been reported.
446446
If you spotted it first, help us to smash it by providing a detailed and welcomed
447-
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_pivot_computed_measure%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
447+
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_pivot_computed_measure%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
448448
<p>Do not contact contributors directly about support or help with technical issues.</p>
449449
</div>
450450
<div class="section" id="credits">
@@ -478,7 +478,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
478478
promote its widespread use.</p>
479479
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
480480
<p><a class="reference external image-reference" href="https://github.com/CarlosRoca13"><img alt="CarlosRoca13" src="https://github.com/CarlosRoca13.png?size=40px" /></a></p>
481-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/18.0/web_pivot_computed_measure">OCA/web</a> project on GitHub.</p>
481+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/19.0/web_pivot_computed_measure">OCA/web</a> project on GitHub.</p>
482482
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
483483
</div>
484484
</div>

web_pivot_computed_measure/static/src/pivot/pivot_model.esm.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
44

55
import {PivotModel} from "@web/views/pivot/pivot_model";
6+
import {_t} from "@web/core/l10n/translation";
67
import {computeReportMeasures} from "@web/views/utils";
78
import {evalOperation} from "../helpers/utils.esm";
89
import {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
}

web_pivot_computed_measure/static/src/test/test.esm.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ registry.category("web_tour.tours").add("web_pivot_computed_measure_tour", {
77
url: "/odoo",
88
test: true,
99
steps: () => [
10-
{
11-
trigger: ".o_navbar_apps_menu button",
12-
run: "click",
13-
},
14-
{
15-
trigger:
16-
'.o_app[data-menu-xmlid="web_pivot_computed_measure.demo_menu_res_partner_report_pivot"]:visible',
17-
run: "click",
18-
},
1910
{
2011
trigger: '.o_pivot_buttons div[aria-label="Main actions"] button',
2112
run: "click",

web_pivot_computed_measure/tests/test_ui_pivot.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,41 @@ class TestUIPivot(common.HttpCase):
1010
@classmethod
1111
def setUpClass(cls):
1212
res = super().setUpClass()
13+
# Built here instead of relying on demo data, since demo data is not
14+
# guaranteed to be loaded when a module is installed via `-i` (it
15+
# depends on how the calling process configured the database).
16+
cls.partner = cls.env["res.partner"].create(
17+
{
18+
"name": "Pivot Demo",
19+
"partner_latitude": 40.712776,
20+
"partner_longitude": -74.005974,
21+
}
22+
)
23+
cls.view = cls.env["ir.ui.view"].create(
24+
{
25+
"name": "res.partner.report.pivot",
26+
"model": "res.partner",
27+
"arch": """
28+
<pivot string="Partners Table" sample="1">
29+
<field name="active" type="col" />
30+
<field name="name" type="row" />
31+
</pivot>
32+
""",
33+
}
34+
)
35+
cls.action = cls.env["ir.actions.act_window"].create(
36+
{
37+
"name": "Demo Pivot",
38+
"res_model": "res.partner",
39+
"view_mode": "pivot",
40+
"view_id": cls.view.id,
41+
}
42+
)
1343
return res
1444

1545
def test_ui(self):
1646
self.start_tour(
17-
"/odoo",
47+
f"/odoo/action-{self.action.id}",
1848
"web_pivot_computed_measure_tour",
1949
login="admin",
2050
step_delay=1000,

0 commit comments

Comments
 (0)