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

[14.0][FIX] product_multi_company: recompute variant companies #590

Merged

Conversation

ilyasProgrammer
Copy link
Member

@ilyasProgrammer ilyasProgrammer commented Feb 23, 2024

FIX #585
Need to force recompute related product.product company_ids field. Otherwise it takes wrong values from the cache.

@pedrobaeza
Copy link
Member

This doesn't seem the correct approach, as it causes an overhead on all models. Why don't you redefine the field as computed in product variant, like other fields like weight do?

@pedrobaeza pedrobaeza modified the milestones: 13.0, 14.0 Feb 23, 2024
@ilyasProgrammer
Copy link
Member Author

ilyasProgrammer commented Feb 23, 2024

This doesn't seem the correct approach, as it causes an overhead on all models. Why don't you redefine the field as computed in product variant, like other fields like weight do?

Looks like it worked as well.
Updated

Copy link
Contributor

@aleuffre aleuffre left a comment

Choose a reason for hiding this comment

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

Code review, I think this is the correct solution for the problem, just a few minor.

product_multi_company/models/__init__.py Outdated Show resolved Hide resolved
comodel_name="res.company",
relation="product_variant_companies_rel",
compute="_compute_company_ids",
store=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

question: do you think a compute_sudo=True is warranted here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it needs to be computed with current user.

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I understand of the base module, company_ids contains all the companies (including the ones the current user cannot see) and it's company_id that needs to be computed with the current user.

In general, if it needs to be computed with the current user it shouldn't be stored, and the other way around as well, if it's stored, the result shouldn't change depending on the user that last triggered the computation.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Could this just be a related field? I don't know if it would work that way)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is related by default because of inheritance. Even if you make that relation explicit it doesnt work. As well as with store=False.

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't depend on the current user for sure. The problem is that I'm giving you tips blindly, as I don't understand the reported issue and it doesn't seem related to this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there something I can improve in the issue itself to make it clearer? Is there anything in particular that you think is underexplained?

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that I can't reproduce the issue in this runboat:

http://oca-multi-company-14-0-d248a27cd7a5.runboat.odoo-community.org/web#id=40&action=145&model=product.product&view_type=form&cids=&menu_id=250

image

and the error message about company employee rule indicates an issue with other module, not this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

OK, reproduced in base DB.

@ilyasProgrammer ilyasProgrammer force-pushed the 14.0-product_multi_company-fix-585 branch 2 times, most recently from 59e8596 to bb4fcee Compare February 23, 2024 11:51
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

Can you avoid to store the field to see if the error persists?

product_multi_company/readme/CONTRIBUTORS.rst Outdated Show resolved Hide resolved
comodel_name="res.company",
relation="product_variant_companies_rel",
compute="_compute_company_ids",
store=True,
Copy link
Member

Choose a reason for hiding this comment

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

OK, reproduced in base DB.

@ilyasProgrammer
Copy link
Member Author

With store=False error is still there

@pedrobaeza
Copy link
Member

Uhm, that's very weird. This should be an ORM fault, as there's nothing in the business side leading to the problem. OK, restore it and clean commit history, and let me check once again.

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

It seems to work.

I think the inner problem is that in v13 it was falsely assumed that there's no need now to remove the auxiliary model:

https://github.com/OCA/multi-company/blob/12.0/base_multi_company/models/res_company_assignment.py

@pedrobaeza
Copy link
Member

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 14.0-ocabot-merge-pr-590-by-pedrobaeza-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 7866057 into OCA:14.0 Feb 27, 2024
19 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at ec4609a. Thanks a lot for contributing to OCA. ❤️

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

Successfully merging this pull request may close these issues.

Multi-company product variant access error
5 participants