Skip to content

Commit 368d9aa

Browse files
committed
[18.0][FIX] web_pivot_computed_measure: fix fake fields in tests
1 parent 48dc591 commit 368d9aa

File tree

6 files changed

+52
-23
lines changed

6 files changed

+52
-23
lines changed

web_pivot_computed_measure/README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Contributors
109109
- Ernesto Tejeda
110110
- Carlos Roca
111111

112+
- `Kencove <https://www.kencove.com/>`__:
113+
114+
- Mohamed Alkobrosli
115+
112116
Maintainers
113117
-----------
114118

web_pivot_computed_measure/readme/CONTRIBUTORS.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
- Pedro M. Baeza
44
- Ernesto Tejeda
55
- Carlos Roca
6+
7+
- [Kencove](https://www.kencove.com/):
8+
- Mohamed Alkobrosli
9+

web_pivot_computed_measure/static/description/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
460460
<li>Carlos Roca</li>
461461
</ul>
462462
</li>
463+
<li><a class="reference external" href="https://www.kencove.com/">Kencove</a>:<ul>
464+
<li>Mohamed Alkobrosli</li>
465+
</ul>
466+
</li>
463467
</ul>
464468
</div>
465469
<div class="section" id="maintainers">

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global console */
12
/* Copyright 2020 Tecnativa - Alexandre Díaz
23
* Copyright 2022 Tecnativa - Carlos Roca
34
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
@@ -40,18 +41,24 @@ patch(PivotModel.prototype, {
4041
if (measure) {
4142
return Promise.resolve();
4243
}
43-
const fieldM1 = this.metaData.fields[field1];
44-
const fieldM2 = this.metaData.fields[field2];
44+
const fieldM1 = this.metaData.fields?.[field1];
45+
const fieldM2 = this.metaData.fields?.[field2];
46+
47+
if (!fieldM1 || !fieldM2) {
48+
console.error(`Invalid fields: field1=${field1}, field2=${field2}`);
49+
return Promise.reject(new Error("Invalid computed measure fields."));
50+
}
51+
4552
const cmId = "__computed_" + id;
4653
const oper = operation.replace(/m1/g, field1).replace(/m2/g, field2);
4754
const oper_human = operation
4855
.replace(
4956
/m1/g,
50-
fieldM1.__computed_id ? "(" + fieldM1.string + ")" : fieldM1.string
57+
fieldM1.__computed_id ? "(" + fieldM1?.string + ")" : fieldM1?.string
5158
)
5259
.replace(
5360
/m2/g,
54-
fieldM2.__computed_id ? "(" + fieldM2.string + ")" : fieldM2.string
61+
fieldM2.__computed_id ? "(" + fieldM2?.string + ")" : fieldM2?.string
5562
);
5663
const cmTotal = this._computed_measures.push({
5764
field1: field1,

web_pivot_computed_measure/tests/res_users_fake.py

-12
This file was deleted.

web_pivot_computed_measure/tests/test_ui_pivot.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2022 Tecnativa - Carlos Roca
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3-
from odoo_test_helper import FakeModelLoader
43

54
from odoo.tests import common, tagged
65

@@ -10,18 +9,41 @@ class TestUIPivot(common.HttpCase):
109
@classmethod
1110
def setUpClass(cls):
1211
super().setUpClass()
13-
cls.loader = FakeModelLoader(cls.env, cls.__module__)
14-
cls.loader.backup_registry()
15-
from .res_users_fake import ResUsersFake
1612

17-
cls.loader.update_registry((ResUsersFake,))
13+
res_users_model_id = (
14+
cls.env["ir.model"].search([("model", "=", "res.users")]).id
15+
)
16+
cls.env["ir.model.fields"].create(
17+
{
18+
"name": "x_user_year_born",
19+
"model": "res.users",
20+
"field_description": "Year Born",
21+
"ttype": "integer",
22+
"store": False,
23+
"model_id": res_users_model_id,
24+
}
25+
)
26+
cls.env["ir.model.fields"].create(
27+
{
28+
"name": "x_user_year_now",
29+
"model": "res.users",
30+
"field_description": "Year Born",
31+
"ttype": "integer",
32+
"store": False,
33+
"model_id": res_users_model_id,
34+
}
35+
)
36+
cls.env.registry.setup_models(cls.env.cr)
37+
cls.env.registry.init_models(
38+
cls.env.cr, ["res.users"], {"update_custom_fields": True}
39+
)
1840
cls.env["res.users"].create(
1941
{
2042
"name": "User 1",
2143
"login": "us_1",
2244
# Fake fields
23-
"user_year_born": 1998,
24-
"user_year_now": 2022,
45+
"x_user_year_born": 1998,
46+
"x_user_year_now": 2022,
2547
}
2648
)
2749
# Set pivot view to company action

0 commit comments

Comments
 (0)