diff --git a/product_multi_company/README.rst b/product_multi_company/README.rst new file mode 100644 index 00000000000..d03cdbf7fcd --- /dev/null +++ b/product_multi_company/README.rst @@ -0,0 +1,108 @@ +===================== +Product multi-company +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2c62d49dbbf1ea5292ef9a39a4cefb23ed16a6aeaa0c0d21c30746ea6b568bfa + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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 + :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 + :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 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules allows to select in which of the companies you want to use +each of the product templates. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module uses the post and uninstall hooks for updating default +product template security rule. This only means that updating the module +will not restore the security rule this module changes. Only a complete +removal and reinstallation will serve. + +Usage +===== + +On the product form view, go to the "General Information" tab, and put +the companies in which you want to use that product. If none is +selected, the product will be visible in all of them. The default value +is the current one. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- Pedro M. Baeza +- Dave Lasley +- `Tecnativa `__: + + - Vicent Cubells + - Pilar Vargas + +- Denis Roussel +- `Sodexis `__: + + - Prabakaran + - Karthik + +- `Dynapps `__: + + - Bert Van Groenendael + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_multi_company/__init__.py b/product_multi_company/__init__.py new file mode 100644 index 00000000000..3568264f59d --- /dev/null +++ b/product_multi_company/__init__.py @@ -0,0 +1,3 @@ +from . import models +from .hooks import post_init_hook +from .hooks import uninstall_hook diff --git a/product_multi_company/__manifest__.py b/product_multi_company/__manifest__.py new file mode 100644 index 00000000000..8747c963055 --- /dev/null +++ b/product_multi_company/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2015-2016 Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + "name": "Product multi-company", + "summary": "Select individually the product template visibility on each " "company", + "author": "Tecnativa," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/multi-company", + "category": "Product Management", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "depends": ["base_multi_company", "product"], + "data": ["views/product_template_view.xml"], + "post_init_hook": "post_init_hook", + "uninstall_hook": "uninstall_hook", +} diff --git a/product_multi_company/hooks.py b/product_multi_company/hooks.py new file mode 100644 index 00000000000..1a087e8a1c9 --- /dev/null +++ b/product_multi_company/hooks.py @@ -0,0 +1,37 @@ +# Copyright 2015-2016 Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +import logging + +_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.") + + +def post_init_hook(env): + hooks.post_init_hook( + env, + "product.product_comp_rule", + "product.template", + ) + + +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)]" + ), + } + ) diff --git a/product_multi_company/i18n/es.po b/product_multi_company/i18n/es.po new file mode 100644 index 00000000000..7d743f38ee6 --- /dev/null +++ b/product_multi_company/i18n/es.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-15 16:43+0000\n" +"PO-Revision-Date: 2023-10-28 16:01+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "Compañías" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "Compañía" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "" + +#~ msgid "Product Template (Multi-Company)" +#~ msgstr "Plantilla de producto (multi-compañía)" + +#~ msgid "No Companies" +#~ msgstr "No Compañías" + +#~ msgid "Product Category" +#~ msgstr "Categoría de producto" + +#~ msgid "Routes" +#~ msgstr "Rutas" + +#~ msgid "Total routes" +#~ msgstr "Total de rutas" diff --git a/product_multi_company/i18n/fr.po b/product_multi_company/i18n/fr.po new file mode 100644 index 00000000000..7cb8b86c197 --- /dev/null +++ b/product_multi_company/i18n/fr.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-15 16:43+0000\n" +"PO-Revision-Date: 2017-06-15 16:43+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "Sociétés" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "" diff --git a/product_multi_company/i18n/hr.po b/product_multi_company/i18n/hr.po new file mode 100644 index 00000000000..96a992543d0 --- /dev/null +++ b/product_multi_company/i18n/hr.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +# Translators: +# Bole , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-27 07:37+0000\n" +"PO-Revision-Date: 2018-01-27 07:37+0000\n" +"Last-Translator: Bole , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"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" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "Tvrtke" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "" + +#~ msgid "Product Template (Multi-Company)" +#~ msgstr "Predložak proizvoda ( više tvrtki)" diff --git a/product_multi_company/i18n/it.po b/product_multi_company/i18n/it.po new file mode 100644 index 00000000000..e7b2b740990 --- /dev/null +++ b/product_multi_company/i18n/it.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-05-30 13:37+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "Aziende" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "Azienda" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "Prodotto" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" diff --git a/product_multi_company/i18n/nl_NL.po b/product_multi_company/i18n/nl_NL.po new file mode 100644 index 00000000000..f75836750cc --- /dev/null +++ b/product_multi_company/i18n/nl_NL.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +# Translators: +# Peter Hageman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-15 16:43+0000\n" +"PO-Revision-Date: 2017-06-15 16:43+0000\n" +"Last-Translator: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "Bedrijven" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "" + +#~ msgid "Product Template (Multi-Company)" +#~ msgstr "Productsjabloon (Meerdere Bedrijven)" diff --git a/product_multi_company/i18n/product_multi_company.pot b/product_multi_company/i18n/product_multi_company.pot new file mode 100644 index 00000000000..e4bc6c33029 --- /dev/null +++ b/product_multi_company/i18n/product_multi_company.pot @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "" diff --git a/product_multi_company/i18n/pt.po b/product_multi_company/i18n/pt.po new file mode 100644 index 00000000000..e1cee949ea9 --- /dev/null +++ b/product_multi_company/i18n/pt.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_multi_company +# +# Translators: +# Pedro Castro Silva , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-16 07:23+0000\n" +"PO-Revision-Date: 2017-12-16 07:23+0000\n" +"Last-Translator: Pedro Castro Silva , 2017\n" +"Language-Team: Portuguese (https://www.transifex.com/oca/teams/23907/pt/)\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_product__company_ids +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_ids +msgid "Companies" +msgstr "Empresas" + +#. module: product_multi_company +#: model:ir.model.fields,field_description:product_multi_company.field_product_template__company_id +msgid "Company" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_template +msgid "Product" +msgstr "" + +#. module: product_multi_company +#: model:ir.model,name:product_multi_company.model_product_product +msgid "Product Variant" +msgstr "" + +#~ msgid "Product Template (Multi-Company)" +#~ msgstr "Modelo de Produto (Multi-Empresa)" diff --git a/product_multi_company/models/__init__.py b/product_multi_company/models/__init__.py new file mode 100644 index 00000000000..e8d5510091b --- /dev/null +++ b/product_multi_company/models/__init__.py @@ -0,0 +1,5 @@ +# 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 diff --git a/product_multi_company/models/product_product.py b/product_multi_company/models/product_product.py new file mode 100644 index 00000000000..26df219deff --- /dev/null +++ b/product_multi_company/models/product_product.py @@ -0,0 +1,26 @@ +# Copyright 2023 Karthik +# Copyright 2020 Kevin Graveman +# Copyright 2015-2016 Pedro M. Baeza +# 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( + comodel_name="res.company", + column1="product_id", + column2="company_id", + relation="product_product_company_rel", + related="product_tmpl_id.company_ids", + compute_sudo=True, + 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) diff --git a/product_multi_company/models/product_template.py b/product_multi_company/models/product_template.py new file mode 100644 index 00000000000..8596b577deb --- /dev/null +++ b/product_multi_company/models/product_template.py @@ -0,0 +1,9 @@ +# Copyright 2015-2016 Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = ["multi.company.abstract", "product.template"] + _name = "product.template" diff --git a/product_multi_company/pyproject.toml b/product_multi_company/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_multi_company/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_multi_company/readme/CONTRIBUTORS.md b/product_multi_company/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..6f967891800 --- /dev/null +++ b/product_multi_company/readme/CONTRIBUTORS.md @@ -0,0 +1,11 @@ +- Pedro M. Baeza \<\> +- Dave Lasley \<\> +- [Tecnativa](https://www.tecnativa.com): + - Vicent Cubells \<\> + - Pilar Vargas +- Denis Roussel \<\> +- [Sodexis](https://sodexis.com): + - Prabakaran \<\> + - Karthik \<\> +- [Dynapps](https://www.dynapps.eu): + - Bert Van Groenendael \<\> diff --git a/product_multi_company/readme/DESCRIPTION.md b/product_multi_company/readme/DESCRIPTION.md new file mode 100644 index 00000000000..266878a0825 --- /dev/null +++ b/product_multi_company/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This modules allows to select in which of the companies you want to use +each of the product templates. diff --git a/product_multi_company/readme/INSTALL.md b/product_multi_company/readme/INSTALL.md new file mode 100644 index 00000000000..22f0dddac74 --- /dev/null +++ b/product_multi_company/readme/INSTALL.md @@ -0,0 +1,4 @@ +This module uses the post and uninstall hooks for updating default +product template security rule. This only means that updating the module +will not restore the security rule this module changes. Only a complete +removal and reinstallation will serve. diff --git a/product_multi_company/readme/USAGE.md b/product_multi_company/readme/USAGE.md new file mode 100644 index 00000000000..8b574e90862 --- /dev/null +++ b/product_multi_company/readme/USAGE.md @@ -0,0 +1,4 @@ +On the product form view, go to the "General Information" tab, and put +the companies in which you want to use that product. If none is +selected, the product will be visible in all of them. The default value +is the current one. diff --git a/product_multi_company/static/description/icon.png b/product_multi_company/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_multi_company/static/description/icon.png differ diff --git a/product_multi_company/static/description/index.html b/product_multi_company/static/description/index.html new file mode 100644 index 00000000000..5c61930cd93 --- /dev/null +++ b/product_multi_company/static/description/index.html @@ -0,0 +1,456 @@ + + + + + +Product multi-company + + + +
+

Product multi-company

+ + +

Beta License: AGPL-3 OCA/multi-company Translate me on Weblate Try me on Runboat

+

This modules allows to select in which of the companies you want to use +each of the product templates.

+

Table of contents

+ +
+

Installation

+

This module uses the post and uninstall hooks for updating default +product template security rule. This only means that updating the module +will not restore the security rule this module changes. Only a complete +removal and reinstallation will serve.

+
+
+

Usage

+

On the product form view, go to the “General Information” tab, and put +the companies in which you want to use that product. If none is +selected, the product will be visible in all of them. The default value +is the current one.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/product_multi_company/tests/__init__.py b/product_multi_company/tests/__init__.py new file mode 100644 index 00000000000..ac02b63c825 --- /dev/null +++ b/product_multi_company/tests/__init__.py @@ -0,0 +1,2 @@ +from . import common +from . import test_product_multi_company diff --git a/product_multi_company/tests/common.py b/product_multi_company/tests/common.py new file mode 100644 index 00000000000..0e5c24f85f8 --- /dev/null +++ b/product_multi_company/tests/common.py @@ -0,0 +1,64 @@ +# Copyright 2015-2016 Pedro M. Baeza +# Copyright 2021 ACSONE SA/NV () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + + +class ProductMultiCompanyCommon: + @classmethod + def _create_products(cls): + cls.product_obj = cls.env["product.product"] + cls.product_company_none = cls.product_obj.create( + { + "name": "Product without company", + } + ) + cls.product_company_1 = cls.product_obj.with_company(cls.company_1).create( + { + "name": "Product from company 1", + "company_ids": [(6, 0, cls.company_1.ids)], + } + ) + cls.product_company_2 = cls.product_obj.with_company(cls.company_2).create( + { + "name": "Product from company 2", + "company_ids": [(6, 0, cls.company_2.ids)], + } + ) + cls.product_company_both = cls.product_obj.create( + { + "name": "Product for both companies", + "company_ids": [(6, 0, (cls.company_1 + cls.company_2).ids)], + } + ) + + @classmethod + def _create_users(cls): + cls.user_company_1 = cls.env["res.users"].create( + { + "name": "User company 1", + "login": "user_company_1", + "groups_id": [(6, 0, cls.groups.ids)], + "company_id": cls.company_1.id, + "company_ids": [(6, 0, cls.company_1.ids)], + } + ) + cls.user_company_2 = cls.env["res.users"].create( + { + "name": "User company 2", + "login": "user_company_2", + "groups_id": [(6, 0, cls.groups.ids)], + "company_id": cls.company_2.id, + "company_ids": [(6, 0, cls.company_2.ids)], + } + ) + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.groups = cls.env.ref("base.group_system") + cls.company_obj = cls.env["res.company"] + cls.company_1 = cls.company_obj.create({"name": "Test company 1"}) + cls.company_2 = cls.company_obj.create({"name": "Test company 2"}) + cls._create_products() + cls._create_users() diff --git a/product_multi_company/tests/test_product_multi_company.py b/product_multi_company/tests/test_product_multi_company.py new file mode 100644 index 00000000000..3ae60f1a9de --- /dev/null +++ b/product_multi_company/tests/test_product_multi_company.py @@ -0,0 +1,153 @@ +# Copyright 2015-2016 Pedro M. Baeza +# Copyright 2021 ACSONE SA/NV () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo.exceptions import AccessError +from odoo.tests import Form, common + +from .common import ProductMultiCompanyCommon + + +class TestProductMultiCompany(ProductMultiCompanyCommon, common.TransactionCase): + def test_create_product(self): + product = self.env["product.product"].create({"name": "Test"}) + self.assertFalse(product.company_id) + self.assertFalse(product.company_ids) + + def test_company_none(self): + self.assertFalse(self.product_company_none.company_id) + # All of this should be allowed + self.product_company_none.with_user( + self.user_company_1.id + ).description_sale = "Test 1" + self.product_company_none.with_user( + self.user_company_2.id + ).description_sale = "Test 2" + + def test_company_none_product_variant(self): + self.assertFalse(self.product_company_none.product_variant_id.company_id) + # All of this should be allowed + Form( + self.product_company_none.product_variant_id.with_user(self.user_company_1) + ) + Form( + self.product_company_none.product_variant_id.with_user(self.user_company_2) + ) + + def test_company_1(self): + self.assertEqual( + self.product_company_1.with_user(self.user_company_1).company_id, + self.company_1, + ) + # All of this should be allowed + self.product_company_1.with_user( + self.user_company_1 + ).description_sale = "Test 1" + self.product_company_both.with_user( + self.user_company_1 + ).description_sale = "Test 2" + # And this one not + with self.assertRaises(AccessError): + self.product_company_2.with_user( + self.user_company_1 + ).description_sale = "Test 3" + + def test_company_1_product_variant(self): + self.assertEqual( + self.product_company_1.product_variant_id.with_user( + self.user_company_1 + ).company_id, + self.company_1, + ) + # All of this should be allowed + Form(self.product_company_1.product_variant_id.with_user(self.user_company_1)) + Form( + self.product_company_both.product_variant_id.with_user(self.user_company_1) + ) + # And this one not + with self.assertRaises(AccessError): + Form( + self.product_company_2.product_variant_id.with_user(self.user_company_1) + ) + + def test_company_2(self): + self.assertEqual( + self.product_company_2.with_user(self.user_company_2).company_id, + self.company_2, + ) + # All of this should be allowed + self.product_company_2.with_user( + self.user_company_2 + ).description_sale = "Test 1" + self.product_company_both.with_user( + self.user_company_2 + ).description_sale = "Test 2" + # And this one not + with self.assertRaises(AccessError): + self.product_company_1.with_user( + self.user_company_2 + ).description_sale = "Test 3" + + def test_company_2_product_variant(self): + self.assertEqual( + self.product_company_2.product_variant_id.with_user( + self.user_company_2 + ).company_id, + self.company_2, + ) + # All of this should be allowed + Form(self.product_company_2.product_variant_id.with_user(self.user_company_2)) + Form( + self.product_company_both.product_variant_id.with_user(self.user_company_2) + ) + # And this one not + with self.assertRaises(AccessError): + Form( + self.product_company_1.product_variant_id.with_user(self.user_company_2) + ) + + def test_product_write(self): + # Companies on variants not may be different compared to their templates + self.product_company_both.write({"company_ids": [(6, 0, self.company_1.ids)]}) + self.assertEqual( + self.product_company_both.company_ids, + 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) + rule = self.env.ref("product.product_comp_rule") + domain = ( + " ['|', ('company_id', 'parent_of', company_ids), " + "('company_id', '=', False)]" + ) + self.assertEqual(rule.domain_force, domain) diff --git a/product_multi_company/views/product_template_view.xml b/product_multi_company/views/product_template_view.xml new file mode 100644 index 00000000000..7ccbf7c1b25 --- /dev/null +++ b/product_multi_company/views/product_template_view.xml @@ -0,0 +1,31 @@ + + + + Product template form view (with multi-company) + product.template + + + + 1 + + + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..0a9feb48042 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-base_multi_company @ git+https://github.com/OCA/multi-company.git@refs/pull/708/head#subdirectory=base_multi_company