Skip to content

Commit

Permalink
[FIX] product_multi_company: don't change rules, but respect previous…
Browse files Browse the repository at this point in the history
… company assignments

Remove lots of code thanks to #760.

Also, call the new `fill_company_ids` hook, to respect company assignments done before the module installation.

@moduon MT-8873
  • Loading branch information
yajo committed Jan 29, 2025
1 parent 5c0a6cf commit 02edfb3
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 64 deletions.
4 changes: 4 additions & 0 deletions product_multi_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Contributors
* Prabakaran <[email protected]>
* Karthik <[email protected]>

* `Moduon <https://www.moduon.team/>`__:

* Jairo Llopis

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

Expand Down
1 change: 0 additions & 1 deletion product_multi_company/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import models
from .hooks import post_init_hook
from .hooks import uninstall_hook
1 change: 0 additions & 1 deletion product_multi_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
"depends": ["base_multi_company", "product"],
"data": ["views/product_template_view.xml"],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
30 changes: 3 additions & 27 deletions product_multi_company/hooks.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)

try:
from odoo.addons.base_multi_company import hooks
except ImportError:
_logger.info("Cannot find `base_multi_company` module in addons path.")
from odoo.addons.base_multi_company import hooks


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
# Change access rule
rule = env.ref("product.product_comp_rule")
rule.write(
{
"domain_force": (
"['|', ('company_ids', 'in', company_ids),"
"('company_ids', '=', False)]"
),
}
)


def uninstall_hook(cr, registry):
hooks.uninstall_hook(
cr,
"product.product_comp_rule",
)
api.Environment(cr, SUPERUSER_ID, {})
hooks.fill_company_ids(cr, "product.template")
1 change: 0 additions & 1 deletion product_multi_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import product_product
from . import product_template
26 changes: 0 additions & 26 deletions product_multi_company/models/product_product.py

This file was deleted.

4 changes: 4 additions & 0 deletions product_multi_company/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@

* Prabakaran <[email protected]>
* Karthik <[email protected]>

* `Moduon <https://www.moduon.team/>`__:

* Jairo Llopis
4 changes: 4 additions & 0 deletions product_multi_company/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Karthik &lt;<a class="reference external" href="mailto:karthik&#64;sodexis.com">karthik&#64;sodexis.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.moduon.team/">Moduon</a>:<ul>
<li>Jairo Llopis</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
8 changes: 0 additions & 8 deletions product_multi_company/tests/test_product_multi_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,3 @@ def test_search_product(self):
]
)
self.assertEqual(searched_products, expected_products)

def test_uninstall(self):
from ..hooks import uninstall_hook

uninstall_hook(self.env.cr, None)
rule = self.env.ref("product.product_comp_rule")
domain = " [('company_id', 'in', [False, user.company_id.id])]"
self.assertEqual(rule.domain_force, domain)

0 comments on commit 02edfb3

Please sign in to comment.