Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][FIX] web_pivot_computed_measure: fix fake fields in tests #3038

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

kobros-tech
Copy link

This fix is the cause for not merging a new migration for web_responsive module to version 18.0.
The migration PR is #3037

@OCA-git-bot
Copy link
Contributor

Hi @CarlosRoca13,
some modules you are maintaining are being modified, check this out!

@kobros-tech kobros-tech force-pushed the 18.0-fix-web_pivot_computed_measure-1 branch 5 times, most recently from 2c27331 to 509ef61 Compare December 24, 2024 22:23
@kobros-tech
Copy link
Author

I am finding this error all the way:

2024-12-25 07:26:39,542 54005 INFO web_responsive_9 odoo.addons.web_pivot_computed_measure.tests.test_ui_pivot.TestUIPivot.test_ui: waiting for threads: []
2024-12-25 07:26:39,544 54005 INFO web_responsive_9 odoo.addons.web_pivot_computed_measure.tests.test_ui_pivot: ======================================================================
2024-12-25 07:26:39,544 54005 ERROR web_responsive_9 odoo.addons.web_pivot_computed_measure.tests.test_ui_pivot: FAIL: TestUIPivot.test_ui
Traceback (most recent call last):
File "/home/kobros/Workspace/odoo18/web/web_pivot_computed_measure/tests/test_ui_pivot.py", line 62, in test_ui
self.start_tour(
File "/home/kobros/Workspace/odoo18/odoo/odoo/tests/common.py", line 2076, in start_tour
return self.browser_js(url_path=url_path, code=code, ready=ready, timeout=timeout, success_signal="tour succeeded", **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kobros/Workspace/odoo18/odoo/odoo/tests/common.py", line 2052, in browser_js
self.fail('%s\n\n%s' % (message, error))
AssertionError: The test code "odoo.startTour('web_pivot_computed_measure_tour', {"stepDelay": 100, "keepWatchBrowser": false, "debug": false, "startUrl": "/odoo", "delayToCheckUndeterminisms": 0})" failed

UncaughtTypeError: Cannot read properties of undefined (reading '__computed_id')
at PivotModel.addComputedMeasure (http://127.0.0.1:8069/web/assets/06ae128/web.assets_backend_lazy.min.js:375:229)
at DropdownItemCustomMeasure.addMeasure (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:14672:150)
at Object.mainEventHandler (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:1603:77)
at HTMLButtonElement.listener (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:762:15)
at dispatch (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15204:71)
at triggerClick (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15132:94)
at _pointerUp (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15187:24)
at async _click (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15141:456)
at async Object.click (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15197:187)
at async TourHelpers.click (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:14733:72)
at addComputedMeasure (http://127.0.0.1:8069/web/assets/06ae128/web.assets_backend_lazy.min.js:374:228)
at addMeasure (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:14671:149)
at mainEventHandler (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:1602:76)
at listener (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:761:14)
at dispatch (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15203:70)
at triggerClick (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15131:93)
at _pointerUp (http://127.0.0.1:8069/web/assets/aeba509/web.assets_web.min.js:15186:23)

This external module was important for the test:
websocket-client

with it being installed test failed, without it test didn't run!

Comment on lines 219 to 222
if (fieldDef && fieldDef.__computed_id) {
const cm = this._computed_measures.find((item) => {
return item.id === fieldDef.__computed_id;
});
toAnalyze.push(cm.field1, cm.field2);
const toEnableFields = [];
if (!this.metaData.fields[cm.field1].__computed_id) {
toEnableFields.push(cm.field1);
}
if (!this.metaData.fields[cm.field2].__computed_id) {
toEnableFields.push(cm.field2);
if (fieldDef) {
if (fieldDef.__computed_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the same? You can use the shorter form. Anyway this change isn't needed IMO

if (fieldDef?.__computed_id)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sure

@@ -275,17 +288,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimize the diff

Suggested change
if (field.__computed_id) {
if (field?.__computed_id) {

} else {
console.warn(
`Field "${fieldName}" is missing __computed_id`,
field
);
}
} else {
console.error(`Field "${fieldName}" is undefined in metaData.fields`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these warnings and errors of any use? If this is a corner case where the code is executed but those variables aren't ready, probably the best thing to do is just to ignore it...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test is not aligned with the code, there maybe some promises not functioning.

I tried but I failed as I am not the maintainer, I need help to improve the test case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CarlosRoca13 is on holidays these days. Maybe when he comes back could give you some hints 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chienandalu yes, thanks to you too much for being interested.
Happy New Year

Comment on lines 1 to 4
# Copyright 2022 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry sorry, I don't mean to ignore the author :)

Comment on lines +14 to +38

# res_users_model_id = (
# cls.env["ir.model"].search([("model", "=", "res.users")]).id
# )
# cls.env["ir.model.fields"].create(
# {
# "name": "x_user_year_born",
# "model": "res.users",
# "field_description": "Year Born",
# "ttype": "integer",
# "store": True,
# "model_id": res_users_model_id,
# }
# )
# cls.env["ir.model.fields"].create(
# {
# "name": "x_user_year_now",
# "model": "res.users",
# "field_description": "Year Now",
# "ttype": "integer",
# "store": True,
# "model_id": res_users_model_id,
# }
# )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it?

Suggested change
# res_users_model_id = (
# cls.env["ir.model"].search([("model", "=", "res.users")]).id
# )
# cls.env["ir.model.fields"].create(
# {
# "name": "x_user_year_born",
# "model": "res.users",
# "field_description": "Year Born",
# "ttype": "integer",
# "store": True,
# "model_id": res_users_model_id,
# }
# )
# cls.env["ir.model.fields"].create(
# {
# "name": "x_user_year_now",
# "model": "res.users",
# "field_description": "Year Now",
# "ttype": "integer",
# "store": True,
# "model_id": res_users_model_id,
# }
# )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chienandalu

I am leaving my comment, as the original code is using a model and we get asked about the fields for this model.

We must create fake fields as while migrating another module errors came from the tests here.

user_year_now, and user_year_born fields

Check this PR please: #3037

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, kinda makes sense without having an in depth look

@kobros-tech kobros-tech force-pushed the 18.0-fix-web_pivot_computed_measure-1 branch from 1c85a7b to 6512a83 Compare December 30, 2024 15:22
@kobros-tech
Copy link
Author

@chienandalu see here:

at async TourHelpers.click (http://127.0.0.1:8069/web/assets/1a839a2/web.assets_web.min.js:10674:72) 

2024-12-30 15:24:55,997 250 ERROR odoo odoo.addons.web_pivot_computed_measure.tests.test_ui_pivot: FAIL: TestUIPivot.test_ui
Traceback (most recent call last):
File "/__w/web/web/web_pivot_computed_measure/tests/test_ui_pivot.py", line 63, in test_ui
self.start_tour(
File "/opt/odoo/odoo/tests/common.py", line 2076, in start_tour
return self.browser_js(url_path=url_path, code=code, ready=ready, timeout=timeout, success_signal="tour succeeded", **kwargs)
File "/opt/odoo/odoo/tests/common.py", line 2052, in browser_js
self.fail('%s\n\n%s' % (message, error))
AssertionError: The test code "odoo.startTour('web_pivot_computed_measure_tour', {"stepDelay": 100, "keepWatchBrowser": false, "debug": false, "startUrl": "/odoo", "delayToCheckUndeterminisms": 0})" failed

UncaughtTypeError: Cannot read properties of undefined (reading '__computed_id')

test fails, I can remove my commented code but I wanted to show you both errors
1 creating a model in db instead of creating fake fields
2 tour test failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants