diff --git a/sale_partner_company_group/README.rst b/sale_partner_company_group/README.rst new file mode 100644 index 000000000000..be0784bc6f61 --- /dev/null +++ b/sale_partner_company_group/README.rst @@ -0,0 +1,83 @@ +========================== +Sale Partner Company Group +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:87e1f50f292cb89c1aa5dcf9af87ffcfd061bc15b6b110b6aea1d6cc05b4f4b6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/17.0/sale_partner_company_group + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-sale_partner_company_group + :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/partner-contact&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This Module adds a company group field to sale orders. For more details +investigate in base_partner_company_group. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Camptocamp SA + +Contributors +------------ + +- Timon Tschanz +- Yannick Vaucher +- `Tecnativa `__: + + - Ernesto Tejeda + +- Tharathip Chaweewongphan + +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/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_partner_company_group/__init__.py b/sale_partner_company_group/__init__.py new file mode 100644 index 000000000000..6d58305f5ddc --- /dev/null +++ b/sale_partner_company_group/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import pre_init_hook diff --git a/sale_partner_company_group/__manifest__.py b/sale_partner_company_group/__manifest__.py new file mode 100644 index 000000000000..297988d368d0 --- /dev/null +++ b/sale_partner_company_group/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Sale Partner Company Group", + "summary": "Adds the possibility to add a company group to a company", + "version": "17.0.1.0.0", + "category": "Sales", + "author": "Camptocamp SA, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["base_partner_company_group", "sale"], + "website": "https://github.com/OCA/partner-contact", + "data": ["views/sale_order_view.xml"], + "installable": True, +} diff --git a/sale_partner_company_group/hooks.py b/sale_partner_company_group/hooks.py new file mode 100644 index 000000000000..62ceef344222 --- /dev/null +++ b/sale_partner_company_group/hooks.py @@ -0,0 +1,15 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging + + +def pre_init_hook(env): + """Prepopulate stored related fields for faster installation""" + logger = logging.getLogger(__name__) + logger.info("Prepopulating stored related fields") + env.execute( + """ + ALTER TABLE sale_order + ADD COLUMN IF NOT EXISTS company_group_id integer; + """ + ) diff --git a/sale_partner_company_group/i18n/es.po b/sale_partner_company_group/i18n/es.po new file mode 100644 index 000000000000..90b2b52c30f0 --- /dev/null +++ b/sale_partner_company_group/i18n/es.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_company_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-08-31 08:13+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\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: sale_partner_company_group +#: model_terms:ir.ui.view,arch_db:sale_partner_company_group.view_sales_order_filter +msgid "Company Group" +msgstr "Grupo compañía" + +#. module: sale_partner_company_group +#: model:ir.model.fields,field_description:sale_partner_company_group.field_sale_order__company_group_id +msgid "Company group" +msgstr "Grupo compañía" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" + +#. module: sale_partner_company_group +#. odoo-python +#: code:addons/sale_partner_company_group/models/res_partner.py:0 +#, python-format +msgid "Warning" +msgstr "Aviso" diff --git a/sale_partner_company_group/i18n/it.po b/sale_partner_company_group/i18n/it.po new file mode 100644 index 000000000000..bb061d3d63ef --- /dev/null +++ b/sale_partner_company_group/i18n/it.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_company_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-27 09: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: sale_partner_company_group +#: model_terms:ir.ui.view,arch_db:sale_partner_company_group.view_sales_order_filter +msgid "Company Group" +msgstr "Azienda capogruppo" + +#. module: sale_partner_company_group +#: model:ir.model.fields,field_description:sale_partner_company_group.field_sale_order__company_group_id +msgid "Company group" +msgstr "Azienda capogruppo" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_partner_company_group +#. odoo-python +#: code:addons/sale_partner_company_group/models/res_partner.py:0 +#, python-format +msgid "Warning" +msgstr "Attenzione" diff --git a/sale_partner_company_group/i18n/pt_BR.po b/sale_partner_company_group/i18n/pt_BR.po new file mode 100644 index 000000000000..ac918b5f9d39 --- /dev/null +++ b/sale_partner_company_group/i18n/pt_BR.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_company_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-28 23:41+0000\n" +"Last-Translator: Adriano Prado \n" +"Language-Team: none\n" +"Language: pt_BR\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: sale_partner_company_group +#: model_terms:ir.ui.view,arch_db:sale_partner_company_group.view_sales_order_filter +msgid "Company Group" +msgstr "Grupo Empresarial" + +#. module: sale_partner_company_group +#: model:ir.model.fields,field_description:sale_partner_company_group.field_sale_order__company_group_id +msgid "Company group" +msgstr "Grupo Empresarial" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_res_partner +msgid "Contact" +msgstr "Contato" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_sale_order +msgid "Sales Order" +msgstr "Pedidos Venda" + +#. module: sale_partner_company_group +#. odoo-python +#: code:addons/sale_partner_company_group/models/res_partner.py:0 +#, python-format +msgid "Warning" +msgstr "Aviso" diff --git a/sale_partner_company_group/i18n/sale_partner_company_group.pot b/sale_partner_company_group/i18n/sale_partner_company_group.pot new file mode 100644 index 000000000000..325ea8944b57 --- /dev/null +++ b/sale_partner_company_group/i18n/sale_partner_company_group.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_company_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: sale_partner_company_group +#: model_terms:ir.ui.view,arch_db:sale_partner_company_group.view_sales_order_filter +msgid "Company Group" +msgstr "" + +#. module: sale_partner_company_group +#: model:ir.model.fields,field_description:sale_partner_company_group.field_sale_order__company_group_id +msgid "Company group" +msgstr "" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_res_partner +msgid "Contact" +msgstr "" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_partner_company_group +#. odoo-python +#: code:addons/sale_partner_company_group/models/res_partner.py:0 +#, python-format +msgid "Warning" +msgstr "" diff --git a/sale_partner_company_group/i18n/zh_CN.po b/sale_partner_company_group/i18n/zh_CN.po new file mode 100644 index 000000000000..ad9f7fbcfbeb --- /dev/null +++ b/sale_partner_company_group/i18n/zh_CN.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_company_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-03-21 14:13+0000\n" +"Last-Translator: Dong \n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.10\n" + +#. module: sale_partner_company_group +#: model_terms:ir.ui.view,arch_db:sale_partner_company_group.view_sales_order_filter +msgid "Company Group" +msgstr "集团公司" + +#. module: sale_partner_company_group +#: model:ir.model.fields,field_description:sale_partner_company_group.field_sale_order__company_group_id +msgid "Company group" +msgstr "集团公司" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_res_partner +msgid "Contact" +msgstr "" + +#. module: sale_partner_company_group +#: model:ir.model,name:sale_partner_company_group.model_sale_order +msgid "Sales Order" +msgstr "销售订单" + +#. module: sale_partner_company_group +#. odoo-python +#: code:addons/sale_partner_company_group/models/res_partner.py:0 +#, python-format +msgid "Warning" +msgstr "" diff --git a/sale_partner_company_group/models/__init__.py b/sale_partner_company_group/models/__init__.py new file mode 100644 index 000000000000..c0ee8511953f --- /dev/null +++ b/sale_partner_company_group/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order +from . import res_partner diff --git a/sale_partner_company_group/models/res_partner.py b/sale_partner_company_group/models/res_partner.py new file mode 100644 index 000000000000..7ee5d744083b --- /dev/null +++ b/sale_partner_company_group/models/res_partner.py @@ -0,0 +1,60 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models + + +class Contact(models.Model): + _inherit = "res.partner" + + @api.onchange("company_group_id") + def _onchange_company_group_id(self): + res = {} + if ( + self.company_group_id + and self.company_group_id.property_product_pricelist + != self.property_product_pricelist + ): + price_list = self.company_group_id.property_product_pricelist + res["warning"] = { + "title": _("Warning"), + "message": _( + "The company group %(company_group)s has" + " the pricelist %(pricelist)s, that is different" + " than the pricelist set on this contact" + ) + % { + "company_group": self.company_group_id.display_name, + "pricelist": price_list.display_name, + }, + } + return res + + @api.onchange("property_product_pricelist") + def _onchange_property_product_pricelist(self): + res = self._onchange_company_group_id() + if ( + not res + and self.company_group_member_ids + # Need to check _origin because the field company_group_ids is a recordset + # of NewIds that have False values on the field property_product_pricelist. + and self.company_group_member_ids._origin.mapped( + "property_product_pricelist" + ) + - self.property_product_pricelist + ): + company_members = self.company_group_member_ids.filtered( + lambda cm: cm.property_product_pricelist + != self.property_product_pricelist + ) + members_str = "" + for member in company_members.sorted(key="display_name"): + members_str += "\t- %s\n" % member.display_name + res["warning"] = { + "title": _("Warning"), + "message": _( + "This contact has members of a company group with" + f" different pricelists, the members are:\n{members_str}" + ), + } + return res diff --git a/sale_partner_company_group/models/sale_order.py b/sale_partner_company_group/models/sale_order.py new file mode 100644 index 000000000000..46e5386a4c9c --- /dev/null +++ b/sale_partner_company_group/models/sale_order.py @@ -0,0 +1,12 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + company_group_id = fields.Many2one( + related="partner_id.company_group_id", store=True + ) diff --git a/sale_partner_company_group/pyproject.toml b/sale_partner_company_group/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/sale_partner_company_group/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_partner_company_group/readme/CONTRIBUTORS.md b/sale_partner_company_group/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..ad36b6fb5d1a --- /dev/null +++ b/sale_partner_company_group/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Timon Tschanz \<\> +- Yannick Vaucher \<\> +- [Tecnativa](https://www.tecnativa.com): + - Ernesto Tejeda +- Tharathip Chaweewongphan \<\> diff --git a/sale_partner_company_group/readme/DESCRIPTION.md b/sale_partner_company_group/readme/DESCRIPTION.md new file mode 100644 index 000000000000..05b7f8379920 --- /dev/null +++ b/sale_partner_company_group/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This Module adds a company group field to sale orders. For more details +investigate in base_partner_company_group. diff --git a/sale_partner_company_group/static/description/icon.png b/sale_partner_company_group/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/sale_partner_company_group/static/description/icon.png differ diff --git a/sale_partner_company_group/static/description/index.html b/sale_partner_company_group/static/description/index.html new file mode 100644 index 000000000000..e2fed8efe373 --- /dev/null +++ b/sale_partner_company_group/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Sale Partner Company Group + + + +
+

Sale Partner Company Group

+ + +

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runboat

+

This Module adds a company group field to sale orders. For more details +investigate in base_partner_company_group.

+

Table of contents

+ +
+

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

+
    +
  • Camptocamp SA
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/sale_partner_company_group/tests/__init__.py b/sale_partner_company_group/tests/__init__.py new file mode 100644 index 000000000000..7b51e58586aa --- /dev/null +++ b/sale_partner_company_group/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_partner_company_group diff --git a/sale_partner_company_group/tests/test_sale_partner_company_group.py b/sale_partner_company_group/tests/test_sale_partner_company_group.py new file mode 100644 index 000000000000..ea9d91f00ce7 --- /dev/null +++ b/sale_partner_company_group/tests/test_sale_partner_company_group.py @@ -0,0 +1,116 @@ +# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.addons.base_partner_company_group.tests.test_base_partner_company_group import ( # noqa: E501 + TestBasePartnerCompanyGroup, +) + + +class TestSalePartnerCompanyGroup(TestBasePartnerCompanyGroup): + @classmethod + def setUpClass(cls): + super().setUpClass() + currency = cls.env.ref("base.USD") + cls.pricelist1 = cls.env["product.pricelist"].create( + {"name": "Pricelist 01", "currency_id": currency.id} + ) + cls.pricelist2 = cls.env["product.pricelist"].create( + {"name": "Pricelist 02", "currency_id": currency.id} + ) + cls.company_group1 = cls.env["res.partner"].create( + { + "name": "Company Group 01", + "is_company": True, + "property_product_pricelist": cls.pricelist1.id, + } + ) + cls.company_group2 = cls.env["res.partner"].create( + { + "name": "Company Group 02", + "is_company": True, + "property_product_pricelist": cls.pricelist2.id, + } + ) + cls.partner1 = cls.env["res.partner"].create( + { + "name": "Partner 01", + "is_company": True, + "property_product_pricelist": cls.pricelist1.id, + "company_group_id": cls.company_group1.id, + } + ) + cls.partner2 = cls.env["res.partner"].create( + { + "name": "Partner 02", + "is_company": True, + "property_product_pricelist": cls.pricelist1.id, + "company_group_id": cls.company_group1.id, + } + ) + + def test_01_change_pricelist_partner(self): + self.partner1.property_product_pricelist = self.pricelist2 + res = self.partner1._onchange_property_product_pricelist() + self.assertEqual( + { + "warning": { + "title": "Warning", + "message": "The company group Company Group 01 has the pricelist " + "Pricelist 01 (USD), that is different than the " + "pricelist set on this contact", + } + }, + res, + ) + self.partner1.property_product_pricelist = self.pricelist1 + res = self.partner1._onchange_property_product_pricelist() + self.assertEqual({}, res) + + def test_02_change_company_group_partner(self): + self.partner1.company_group_id = self.company_group2 + res = self.partner1._onchange_company_group_id() + self.assertEqual( + { + "warning": { + "title": "Warning", + "message": "The company group Company Group 02 has the pricelist " + "Pricelist 02 (USD), that is different than the " + "pricelist set on this contact", + } + }, + res, + ) + self.partner1.company_group_id = self.company_group1 + res = self.partner1._onchange_company_group_id() + self.assertEqual({}, res) + + def test_03_change_pricelist_company_group(self): + self.company_group1.property_product_pricelist = self.pricelist2 + res = self.company_group1._onchange_property_product_pricelist() + self.assertEqual( + { + "warning": { + "title": "Warning", + "message": "This contact has members of a company group with " + "different pricelists, the members are:\n" + "\t- Partner 01\n\t- Partner 02\n", + } + }, + res, + ) + self.partner1.property_product_pricelist = self.pricelist2 + res = self.company_group1._onchange_property_product_pricelist() + self.assertEqual( + { + "warning": { + "title": "Warning", + "message": "This contact has members of a company group with " + "different pricelists, the members are:\n" + "\t- Partner 02\n", + } + }, + res, + ) + self.partner2.property_product_pricelist = self.pricelist2 + res = self.company_group1._onchange_property_product_pricelist() + self.assertEqual({}, res) diff --git a/sale_partner_company_group/views/sale_order_view.xml b/sale_partner_company_group/views/sale_order_view.xml new file mode 100644 index 000000000000..2e12c8dc724b --- /dev/null +++ b/sale_partner_company_group/views/sale_order_view.xml @@ -0,0 +1,20 @@ + + + + sale.order.list.select + sale.order + + + + + + + + + + +