Skip to content

Commit

Permalink
[MIG] product_multi_company: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Raf Ven committed Nov 20, 2024
1 parent 60c0991 commit 31991f8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion product_multi_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"category": "Product Management",
"version": "16.0.1.0.2",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"depends": ["base_multi_company", "product"],
"data": ["views/product_template_view.xml"],
Expand Down
39 changes: 21 additions & 18 deletions product_multi_company/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)

try:
Expand All @@ -13,22 +11,27 @@
_logger.info("Cannot find `base_multi_company` module in addons path.")

Check warning on line 11 in product_multi_company/hooks.py

View check run for this annotation

Codecov / codecov/patch

product_multi_company/hooks.py#L10-L11

Added lines #L10 - L11 were not covered by tests


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 post_init_hook(env):
hooks.post_init_hook(
env,
"product.product_comp_rule",
"product.template",
)


def uninstall_hook(cr, registry):
hooks.uninstall_hook(
cr,
"product.product_comp_rule",
)
def uninstall_hook(env):
"""Restore product rule to base value.
Args:
env (Environment): Environment to use for operation.
"""
rule = env.ref("product.product_comp_rule")
if rule: # safeguard if it's deleted
rule.write(
{
"domain_force": (
" ['|', ('company_id', 'parent_of', company_ids),"
" ('company_id', '=', False)]"
),
}
)
4 changes: 2 additions & 2 deletions product_multi_company/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class ProductProduct(models.Model):
)

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def search(self, args, offset=0, limit=None, order=None):
dom = self.env["multi.company.abstract"]._patch_company_domain(args)
return super().search(dom, offset=offset, limit=limit, order=order, count=count)
return super().search(dom, offset=offset, limit=limit, order=order)
1 change: 0 additions & 1 deletion product_multi_company/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def _create_products(cls):
cls.product_company_none = cls.product_obj.create(
{
"name": "Product without company",
"company_id": False,
}
)
cls.product_company_1 = cls.product_obj.with_company(cls.company_1).create(
Expand Down
7 changes: 5 additions & 2 deletions product_multi_company/tests/test_product_multi_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def test_search_product(self):
def test_uninstall(self):
from ..hooks import uninstall_hook

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

0 comments on commit 31991f8

Please sign in to comment.