Skip to content

Commit

Permalink
[18.0][FIX] web_pivot_computed_measure: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kobros-tech committed Jan 24, 2025
1 parent 48dc591 commit 0b4d879
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 53 deletions.
4 changes: 4 additions & 0 deletions web_pivot_computed_measure/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Contributors
- Ernesto Tejeda
- Carlos Roca

- `Kencove <https://www.kencove.com/>`__:

- Mohamed Alkobrosli

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion web_pivot_computed_measure/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"depends": ["web", "account"],
"auto_install": False,
"installable": True,
"maintainers": ["CarlosRoca13"],
Expand Down
4 changes: 4 additions & 0 deletions web_pivot_computed_measure/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
- Pedro M. Baeza
- Ernesto Tejeda
- Carlos Roca

- [Kencove](https://www.kencove.com/):
- Mohamed Alkobrosli

4 changes: 4 additions & 0 deletions web_pivot_computed_measure/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Carlos Roca</li>
</ul>
</li>
<li><a class="reference external" href="https://www.kencove.com/">Kencove</a>:<ul>
<li>Mohamed Alkobrosli</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
36 changes: 26 additions & 10 deletions web_pivot_computed_measure/static/src/pivot/pivot_model.esm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global console */

/* Copyright 2020 Tecnativa - Alexandre Díaz
* Copyright 2022 Tecnativa - Carlos Roca
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
Expand Down Expand Up @@ -216,7 +218,7 @@ patch(PivotModel.prototype, {
const afield = toAnalyze.shift();
const fieldDef = this.metaData.fields[afield];
// Need to check if fieldDef exists to avoid problems with __count
if (fieldDef && fieldDef.__computed_id) {
if (fieldDef?.__computed_id) {
const cm = this._computed_measures.find((item) => {
return item.id === fieldDef.__computed_id;
});
Expand All @@ -230,6 +232,10 @@ patch(PivotModel.prototype, {
}
toEnableFields.push(afield);
toEnable.push(toEnableFields);
} else if (this.env.debug === "1") {
console.error(
`Field "${fieldDef}" is undefined in metaData.fields`
);
}
}
if (toEnable.length) {
Expand Down Expand Up @@ -275,17 +281,27 @@ patch(PivotModel.prototype, {
const fieldNames = Object.keys(this.metaData.fields);
for (const fieldName of fieldNames) {
const field = this.metaData.fields[fieldName];
if (field.__computed_id) {
const cm = this._computed_measures.find((item) => {
return item.id === field.__computed_id;
});
if (!cm) {
delete this.metaData.fields[fieldName];
delete this.metaData.measures[fieldName];
this.metaData.activeMeasures = this.metaData.activeMeasures.filter(
(item) => item !== fieldName
if (field) {
if (field?.__computed_id) {
const cm = this._computed_measures.find(
(item) => item.id === field.__computed_id
);
if (!cm) {
delete this.metaData.fields[fieldName];
delete this.metaData.measures[fieldName];
this.metaData.activeMeasures =
this.metaData.activeMeasures.filter(
(item) => item !== fieldName
);
}
} else if (this.env.debug === "1") {
console.warn(
`Field "${fieldName}" is missing __computed_id`,
field
);
}
} else if (this.env.debug === "1") {
console.error(`Field "${fieldName}" is undefined in metaData.fields`);
}
}
return _super(...arguments);
Expand Down
26 changes: 14 additions & 12 deletions web_pivot_computed_measure/static/src/test/test.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ registry.category("web_tour.tours").add("web_pivot_computed_measure_tour", {
run: "click",
},
{
trigger: '.o_app[data-menu-xmlid="base.menu_administration"]',
trigger: '.o_app[data-menu-xmlid="account.menu_finance"]',
run: "click",
},
{
trigger: 'button[data-menu-xmlid="base.menu_users"]',
trigger: 'button[data-menu-xmlid="account.menu_finance_reports"]',
run: "click",
},
{
trigger: 'a[data-menu-xmlid="base.menu_action_res_users"]',
trigger:
'a[data-menu-xmlid="account.menu_action_account_invoice_report_all"]',
run: "click",
},
{
Expand All @@ -37,13 +38,13 @@ registry.category("web_tour.tours").add("web_pivot_computed_measure_tour", {
{
trigger: "select#computed_measure_field_1",
run() {
this.anchor.value = "user_year_now";
this.anchor.value = "price_subtotal";
},
},
{
trigger: "select#computed_measure_field_2",
run() {
this.anchor.value = "user_year_born";
this.anchor.value = "price_total";
},
},
{
Expand All @@ -55,30 +56,31 @@ registry.category("web_tour.tours").add("web_pivot_computed_measure_tour", {
{
trigger: "select#computed_measure_format",
run() {
this.anchor.value = "integer";
this.anchor.value = "float";
},
},
{
trigger: "button.o_add_computed_measure",
run: "click",
},
{
trigger: 'th.o_pivot_measure_row:contains("User Year Now")',
trigger: 'th.o_pivot_measure_row:contains("Untaxed Amount")',
},
{
trigger: 'div.o_value:contains("2,022")',
trigger: 'th.o_pivot_measure_row:contains("Total in Currency")',
},
{
trigger: 'th.o_pivot_measure_row:contains("User Year Born")',
trigger:
'th.o_pivot_measure_row:contains("Untaxed Amount-Total in Currency")',
},
{
trigger: 'div.o_value:contains("1,998")',
trigger: 'div.o_value:contains("-31,750.00")',
},
{
trigger: 'th.o_pivot_measure_row:contains("User Year Now-User Year Born")',
trigger: 'div.o_value:contains("-36,512.50")',
},
{
trigger: 'div.o_value:contains("24")',
trigger: 'div.o_value:contains("4,762.50")',
},
],
});
12 changes: 0 additions & 12 deletions web_pivot_computed_measure/tests/res_users_fake.py

This file was deleted.

19 changes: 1 addition & 18 deletions web_pivot_computed_measure/tests/test_ui_pivot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2022 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo_test_helper import FakeModelLoader


from odoo.tests import common, tagged

Expand All @@ -10,23 +10,6 @@ class TestUIPivot(common.HttpCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from .res_users_fake import ResUsersFake

cls.loader.update_registry((ResUsersFake,))
cls.env["res.users"].create(
{
"name": "User 1",
"login": "us_1",
# Fake fields
"user_year_born": 1998,
"user_year_now": 2022,
}
)
# Set pivot view to company action
action = cls.env.ref("base.action_res_users")
action.view_mode += ",pivot"

def test_ui(self):
self.start_tour(
Expand Down

0 comments on commit 0b4d879

Please sign in to comment.