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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion product_multi_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Product multi-company
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c0b3d1060c5a3b214c6a2264ef198fd7c40aed60ab30b6c35c6830aa70e3dc0e
!! source digest: sha256:1cb9618b893555cdec0f0b75ac016cd378d12b719a3bf61e8044545cc2ac097a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -78,6 +78,9 @@ Contributors
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Denis Roussel <denis.roussel@acsone.eu>

* Ooops404 <https://ooops404.com>
* Ilyas <irazor147@gmail.com>

Maintainers
~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions product_multi_company/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import product_template
from . import product
from . import product_category
21 changes: 21 additions & 0 deletions product_multi_company/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models


class ProductProduct(models.Model):
_inherit = "product.product"

company_ids = fields.Many2many(
string="Companies",
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.

)

@api.depends("product_tmpl_id.company_ids")
def _compute_company_ids(self):
for rec in self:
rec.company_ids = [(6, 0, rec.product_tmpl_id.company_ids.ids)]
3 changes: 3 additions & 0 deletions product_multi_company/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

* Vicent Cubells <vicent.cubells@tecnativa.com>
* Denis Roussel <denis.roussel@acsone.eu>
* Ooops404 <https://ooops404.com>

* Ilyas <irazor147@gmail.com>
10 changes: 9 additions & 1 deletion product_multi_company/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Product multi-company</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c0b3d1060c5a3b214c6a2264ef198fd7c40aed60ab30b6c35c6830aa70e3dc0e
!! source digest: sha256:1cb9618b893555cdec0f0b75ac016cd378d12b719a3bf61e8044545cc2ac097a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/multi-company/tree/14.0/product_multi_company"><img alt="OCA/multi-company" src="https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/multi-company-14-0/multi-company-14-0-product_multi_company"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/multi-company&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This modules allows to select in which of the companies you want to use each of the product templates.</p>
Expand Down Expand Up @@ -424,6 +424,14 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
</ul>
</li>
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
<li><dl class="first docutils">
<dt>Ooops404 &lt;<a class="reference external" href="https://ooops404.com">https://ooops404.com</a>&gt;</dt>
<dd><ul class="first last">
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
</ul>
</dd>
</dl>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
6 changes: 6 additions & 0 deletions product_multi_company/tests/test_product_multi_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def test_company_none(self):
).description_sale = "Test 2"

def test_company_1(self):
self.product_company_1.product_tmpl_id.company_ids = [
(6, 0, self.company_1.ids)
]
self.assertEqual(
self.product_company_1.with_user(self.user_company_1).company_id,
self.company_1,
Expand All @@ -42,6 +45,9 @@ def test_company_1(self):
).description_sale = "Test 3"

def test_company_2(self):
self.product_company_2.product_tmpl_id.company_ids = [
(6, 0, self.company_2.ids)
]
self.assertEqual(
self.product_company_2.with_user(self.user_company_2).company_id,
self.company_2,
Expand Down
Loading