Skip to content

Commit

Permalink
[18.0][MIG] product_multi_company: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BertVGroenendael committed Nov 22, 2024
1 parent d0cbfa2 commit 489de2e
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 35 deletions.
12 changes: 6 additions & 6 deletions 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:8aecab69fa7d09b29e14ba2967815e73ad8a54e725fac700a6f6e841fd4ba9e1
!! source digest: sha256:2c62d49dbbf1ea5292ef9a39a4cefb23ed16a6aeaa0c0d21c30746ea6b568bfa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Product multi-company
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github
:target: https://github.com/OCA/multi-company/tree/18.0/product_multi_company
:target: https://github.com/OCA/multi-company/tree/17.0/product_multi_company
:alt: OCA/multi-company
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/multi-company-18-0/multi-company-18-0-product_multi_company
:target: https://translation.odoo-community.org/projects/multi-company-17-0/multi-company-17-0-product_multi_company
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/multi-company&target_branch=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/multi-company&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -58,7 +58,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/multi-company/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/multi-company/issues/new?body=module:%20product_multi_company%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/multi-company/issues/new?body=module:%20product_multi_company%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -99,6 +99,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/multi-company <https://github.com/OCA/multi-company/tree/18.0/product_multi_company>`_ project on GitHub.
This module is part of the `OCA/multi-company <https://github.com/OCA/multi-company/tree/17.0/product_multi_company>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
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.")


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/i18n/hr.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"

#. module: product_multi_company
#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids
Expand Down
2 changes: 1 addition & 1 deletion product_multi_company/i18n/product_multi_company.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down
7 changes: 6 additions & 1 deletion product_multi_company/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models
from odoo import api, fields, models


class ProductProduct(models.Model):
Expand All @@ -19,3 +19,8 @@ class ProductProduct(models.Model):
readonly=False,
store=True,
)

@api.model
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)
2 changes: 2 additions & 0 deletions product_multi_company/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
- [Sodexis](https://sodexis.com):
- Prabakaran \<<[email protected]>\>
- Karthik \<<[email protected]>\>
- [Dynapps](https://www.dynapps.eu):
- Bert Van Groenendael \<<[email protected]>\>
8 changes: 4 additions & 4 deletions product_multi_company/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Product multi-company</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8aecab69fa7d09b29e14ba2967815e73ad8a54e725fac700a6f6e841fd4ba9e1
!! source digest: sha256:2c62d49dbbf1ea5292ef9a39a4cefb23ed16a6aeaa0c0d21c30746ea6b568bfa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/18.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-18-0/multi-company-18-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=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<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/17.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-17-0/multi-company-17-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=17.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>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -405,7 +405,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/multi-company/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/multi-company/issues/new?body=module:%20product_multi_company%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/multi-company/issues/new?body=module:%20product_multi_company%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -443,7 +443,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/multi-company/tree/18.0/product_multi_company">OCA/multi-company</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/multi-company/tree/17.0/product_multi_company">OCA/multi-company</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
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
32 changes: 30 additions & 2 deletions product_multi_company/tests/test_product_multi_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,38 @@ def test_product_write(self):
self.product_company_both.product_tmpl_id.company_ids,
)

def test_search_product(self):
"""Products with no company are shared across companies but we need to convert
those queries with an or operator"""
expected_products = (
self.product_company_both
+ self.product_company_1
+ self.product_company_none
)
searched_templates = self.env["product.template"].search(
[
("id", "in", expected_products.product_tmpl_id.ids),
'|', ("company_id", "=", self.company_1.id),
("company_id", "=", False),
]
)
self.assertEqual(searched_templates, expected_products.product_tmpl_id)
searched_products = self.product_obj.search(
[
("id", "in", expected_products.ids),
'|', ("company_id", "=", self.company_1.id),
("company_id", "=", False),
]
)
self.assertEqual(searched_products, expected_products)

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 489de2e

Please sign in to comment.