From 6c4c31e4343231f3aef962b3de23af253c6a0b8e Mon Sep 17 00:00:00 2001 From: kobros-tech Date: Wed, 25 Dec 2024 00:15:27 +0300 Subject: [PATCH] [18.0][FIX] web_pivot_computed_measure: fix tests --- web_pivot_computed_measure/README.rst | 4 ++ web_pivot_computed_measure/__manifest__.py | 3 ++ .../demo/demo_users_pivot_view.xml | 45 +++++++++++++++++++ .../readme/CONTRIBUTORS.md | 4 ++ .../static/description/index.html | 4 ++ .../static/src/pivot/pivot_model.esm.js | 36 ++++++++++----- .../static/src/test/test.esm.js | 35 +++++---------- .../tests/res_users_fake.py | 12 ----- .../tests/test_ui_pivot.py | 22 ++------- 9 files changed, 101 insertions(+), 64 deletions(-) create mode 100644 web_pivot_computed_measure/demo/demo_users_pivot_view.xml delete mode 100644 web_pivot_computed_measure/tests/res_users_fake.py diff --git a/web_pivot_computed_measure/README.rst b/web_pivot_computed_measure/README.rst index 5f895abf97cc..250aa9555d41 100644 --- a/web_pivot_computed_measure/README.rst +++ b/web_pivot_computed_measure/README.rst @@ -109,6 +109,10 @@ Contributors - Ernesto Tejeda - Carlos Roca +- `Kencove `__: + + - Mohamed Alkobrosli + Maintainers ----------- diff --git a/web_pivot_computed_measure/__manifest__.py b/web_pivot_computed_measure/__manifest__.py index 42a177a258fe..ff13ab7acc7e 100644 --- a/web_pivot_computed_measure/__manifest__.py +++ b/web_pivot_computed_measure/__manifest__.py @@ -11,6 +11,9 @@ "auto_install": False, "installable": True, "maintainers": ["CarlosRoca13"], + "demo": [ + "demo/demo_users_pivot_view.xml", + ], "assets": { "web.assets_backend": [ "web_pivot_computed_measure/static/src/**/*.esm.js", diff --git a/web_pivot_computed_measure/demo/demo_users_pivot_view.xml b/web_pivot_computed_measure/demo/demo_users_pivot_view.xml new file mode 100644 index 000000000000..f5bc347c79f2 --- /dev/null +++ b/web_pivot_computed_measure/demo/demo_users_pivot_view.xml @@ -0,0 +1,45 @@ + + + + Pivot Demo + + YourCompany + 3575 Buena Vista Avenue + Eugene + + 97401 + + Europe/Brussels + mark.brown23@example.com + (441)-695-2344 + 40.712776 + -74.005974 + + + + res.partner.report.pivot + res.partner + + + + + + + + + + Demo Pivot + res.partner + pivot + + + + + diff --git a/web_pivot_computed_measure/readme/CONTRIBUTORS.md b/web_pivot_computed_measure/readme/CONTRIBUTORS.md index 5d3768b54ddf..12a4cec67df2 100644 --- a/web_pivot_computed_measure/readme/CONTRIBUTORS.md +++ b/web_pivot_computed_measure/readme/CONTRIBUTORS.md @@ -3,3 +3,7 @@ - Pedro M. Baeza - Ernesto Tejeda - Carlos Roca + +- [Kencove](https://www.kencove.com/): + - Mohamed Alkobrosli + \ No newline at end of file diff --git a/web_pivot_computed_measure/static/description/index.html b/web_pivot_computed_measure/static/description/index.html index 203a83951fd0..9dc5012c2b0c 100644 --- a/web_pivot_computed_measure/static/description/index.html +++ b/web_pivot_computed_measure/static/description/index.html @@ -460,6 +460,10 @@

Contributors

  • Carlos Roca
  • +
  • Kencove:
      +
    • Mohamed Alkobrosli
    • +
    +
  • diff --git a/web_pivot_computed_measure/static/src/pivot/pivot_model.esm.js b/web_pivot_computed_measure/static/src/pivot/pivot_model.esm.js index 3b1cfe3d4011..471b7b730475 100644 --- a/web_pivot_computed_measure/static/src/pivot/pivot_model.esm.js +++ b/web_pivot_computed_measure/static/src/pivot/pivot_model.esm.js @@ -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) */ @@ -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; }); @@ -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) { @@ -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); diff --git a/web_pivot_computed_measure/static/src/test/test.esm.js b/web_pivot_computed_measure/static/src/test/test.esm.js index 81dc10f8791b..ca70c2dc1f51 100644 --- a/web_pivot_computed_measure/static/src/test/test.esm.js +++ b/web_pivot_computed_measure/static/src/test/test.esm.js @@ -11,19 +11,8 @@ registry.category("web_tour.tours").add("web_pivot_computed_measure_tour", { run: "click", }, { - trigger: '.o_app[data-menu-xmlid="base.menu_administration"]', - run: "click", - }, - { - trigger: 'button[data-menu-xmlid="base.menu_users"]', - run: "click", - }, - { - trigger: 'a[data-menu-xmlid="base.menu_action_res_users"]', - run: "click", - }, - { - trigger: "button.o_pivot", + trigger: + '.o_app[data-menu-xmlid="web_pivot_computed_measure.demo_menu_res_partner_report_pivot"]', run: "click", }, { @@ -37,25 +26,25 @@ 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 = "partner_latitude"; }, }, { trigger: "select#computed_measure_field_2", run() { - this.anchor.value = "user_year_born"; + this.anchor.value = "partner_longitude"; }, }, { trigger: "select#computed_measure_operation", run() { - this.anchor.value = "m1-m2"; + this.anchor.value = "m1+m2"; }, }, { trigger: "select#computed_measure_format", run() { - this.anchor.value = "integer"; + this.anchor.value = "float"; }, }, { @@ -63,22 +52,22 @@ registry.category("web_tour.tours").add("web_pivot_computed_measure_tour", { run: "click", }, { - trigger: 'th.o_pivot_measure_row:contains("User Year Now")', + trigger: 'th.o_pivot_measure_row:contains("Geo Latitude")', }, { - trigger: 'div.o_value:contains("2,022")', + trigger: 'th.o_pivot_measure_row:contains("Geo Longitude")', }, { - trigger: 'th.o_pivot_measure_row:contains("User Year Born")', + trigger: 'th.o_pivot_measure_row:contains("Geo Latitude+Geo Longitude")', }, { - trigger: 'div.o_value:contains("1,998")', + trigger: 'div.o_value:contains("40.7127760")', }, { - trigger: 'th.o_pivot_measure_row:contains("User Year Now-User Year Born")', + trigger: 'div.o_value:contains("-74.0059740")', }, { - trigger: 'div.o_value:contains("24")', + trigger: 'div.o_value:contains("-33.29")', }, ], }); diff --git a/web_pivot_computed_measure/tests/res_users_fake.py b/web_pivot_computed_measure/tests/res_users_fake.py deleted file mode 100644 index 4561b79a9c58..000000000000 --- a/web_pivot_computed_measure/tests/res_users_fake.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2022 Tecnativa - Carlos Roca -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) - - -from odoo import fields, models - - -class ResUsersFake(models.Model): - _inherit = "res.users" - - user_year_born = fields.Integer() - user_year_now = fields.Integer() diff --git a/web_pivot_computed_measure/tests/test_ui_pivot.py b/web_pivot_computed_measure/tests/test_ui_pivot.py index 1dc01aebdaf7..57c62758fc4e 100644 --- a/web_pivot_computed_measure/tests/test_ui_pivot.py +++ b/web_pivot_computed_measure/tests/test_ui_pivot.py @@ -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 @@ -9,24 +9,8 @@ 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" + res = super().setUpClass() + return res def test_ui(self): self.start_tour(