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 6c4c31e
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 64 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
3 changes: 3 additions & 0 deletions web_pivot_computed_measure/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 45 additions & 0 deletions web_pivot_computed_measure/demo/demo_users_pivot_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="pivot_partner_demo" model="res.partner">
<field name="name">Pivot Demo</field>
<field name="company_id" ref="base.main_company" />
<field name="company_name">YourCompany</field>
<field name="street">3575 Buena Vista Avenue</field>
<field name="city">Eugene</field>
<field name="state_id" model="res.country.state" search="[('code','=','OR')]" />
<field name="zip">97401</field>
<field name="country_id" ref="base.us" />
<field name="tz">Europe/Brussels</field>
<field name="email">[email protected]</field>
<field name="phone">(441)-695-2344</field>
<field name="partner_latitude">40.712776</field>
<field name="partner_longitude">-74.005974</field>
</record>

<record id="demo_view_res_partner_report_pivot" model="ir.ui.view">
<field name="name">res.partner.report.pivot</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<pivot string="Partners Table" sample="1">
<field name="active" type="col" />
<field name="name" type="row" />
</pivot>
</field>
</record>

<record id="demo_action_res_partner_report_pivot" model="ir.actions.act_window">
<field name="name">Demo Pivot</field>
<field name="res_model">res.partner</field>
<field name="view_mode">pivot</field>
<field
name="view_id"
ref="web_pivot_computed_measure.demo_view_res_partner_report_pivot"
/>
</record>

<menuitem
id="demo_menu_res_partner_report_pivot"
action="web_pivot_computed_measure.demo_action_res_partner_report_pivot"
sequence="10"
/>
</odoo>
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
35 changes: 12 additions & 23 deletions web_pivot_computed_measure/static/src/test/test.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand All @@ -37,48 +26,48 @@ 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";
},
},
{
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("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")',
},
],
});
12 changes: 0 additions & 12 deletions web_pivot_computed_measure/tests/res_users_fake.py

This file was deleted.

22 changes: 3 additions & 19 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 @@ -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(
Expand Down

0 comments on commit 6c4c31e

Please sign in to comment.