From 79fc9a1006fc2968cceb7d8208db32cd86a68df0 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Wed, 31 Jan 2024 14:58:22 +0100 Subject: [PATCH] [ADD] sale_partner_company --- sale_partner_company/README.rst | 92 ++++ sale_partner_company/__init__.py | 1 + sale_partner_company/__manifest__.py | 21 + sale_partner_company/models/__init__.py | 2 + sale_partner_company/models/res_partner.py | 10 + sale_partner_company/models/sale_order.py | 32 ++ sale_partner_company/readme/CONFIGURE.rst | 3 + sale_partner_company/readme/CONTRIBUTORS.rst | 2 + sale_partner_company/readme/DESCRIPTION.rst | 1 + sale_partner_company/readme/USAGE.rst | 1 + .../static/description/index.html | 440 ++++++++++++++++++ sale_partner_company/tests/__init__.py | 1 + .../tests/test_sale_partner_company.py | 33 ++ sale_partner_company/views/partner_view.xml | 13 + .../odoo/addons/sale_partner_company | 1 + setup/sale_partner_company/setup.py | 6 + 16 files changed, 659 insertions(+) create mode 100644 sale_partner_company/README.rst create mode 100644 sale_partner_company/__init__.py create mode 100644 sale_partner_company/__manifest__.py create mode 100644 sale_partner_company/models/__init__.py create mode 100644 sale_partner_company/models/res_partner.py create mode 100644 sale_partner_company/models/sale_order.py create mode 100644 sale_partner_company/readme/CONFIGURE.rst create mode 100644 sale_partner_company/readme/CONTRIBUTORS.rst create mode 100644 sale_partner_company/readme/DESCRIPTION.rst create mode 100644 sale_partner_company/readme/USAGE.rst create mode 100644 sale_partner_company/static/description/index.html create mode 100644 sale_partner_company/tests/__init__.py create mode 100644 sale_partner_company/tests/test_sale_partner_company.py create mode 100644 sale_partner_company/views/partner_view.xml create mode 120000 setup/sale_partner_company/odoo/addons/sale_partner_company create mode 100644 setup/sale_partner_company/setup.py diff --git a/sale_partner_company/README.rst b/sale_partner_company/README.rst new file mode 100644 index 00000000000..5f79a04dd18 --- /dev/null +++ b/sale_partner_company/README.rst @@ -0,0 +1,92 @@ +===================== +sale partner companyy +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/16.0/sale_partner_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-16-0/multi-company-16-0-sale_partner_company + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/multi-company&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Allow to set the default selling company on a partner. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +On the partner, choose the default company. + +Create a sale.order with this partner, the sales company will be adapted from the partner. + +Usage +===== + +You need at least to manage 2 different companies. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp +* BCIM + +Contributors +~~~~~~~~~~~~ + + * Telmo Santos + * Jacques-Etienne Baudoux (BCIM) + +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/sale_partner_company/__init__.py b/sale_partner_company/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_partner_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_partner_company/__manifest__.py b/sale_partner_company/__manifest__.py new file mode 100644 index 00000000000..679ab761793 --- /dev/null +++ b/sale_partner_company/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "sale partner companyy", + "summary": "Set sale company from partner", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Warehouse Management", + "website": "https://github.com/OCA/multi-company", + "author": "Camptocamp, BCIM, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "data": [ + "views/partner_view.xml", + ], + "depends": [ + "sale_stock", + "delivery", + ], +} diff --git a/sale_partner_company/models/__init__.py b/sale_partner_company/models/__init__.py new file mode 100644 index 00000000000..17c6cc85d0c --- /dev/null +++ b/sale_partner_company/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner +from . import sale_order diff --git a/sale_partner_company/models/res_partner.py b/sale_partner_company/models/res_partner.py new file mode 100644 index 00000000000..d3b7f66fcbc --- /dev/null +++ b/sale_partner_company/models/res_partner.py @@ -0,0 +1,10 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + sale_company_id = fields.Many2one("res.company", string="Selling Company") diff --git a/sale_partner_company/models/sale_order.py b/sale_partner_company/models/sale_order.py new file mode 100644 index 00000000000..de8ddb68f42 --- /dev/null +++ b/sale_partner_company/models/sale_order.py @@ -0,0 +1,32 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + company_id = fields.Many2one( + compute="_compute_company_id", + store=True, + precompute=True, + default=lambda self: self._get_default_company(), + ) + + def _get_default_company(self): + default_partner_id = self.env.context.get("default_partner_id") + if default_partner_id: + partner = self.env["res.partner"].browse(default_partner_id) + if partner.sale_company_id: + return partner.sale_company_id.id + else: + return self.env.company.id + + @api.depends("partner_id.sale_company_id") + def _compute_company_id(self): + for sale in self: + if sale.partner_id.sale_company_id: + sale.company_id = sale.partner_id.sale_company_id + else: + sale.company_id = self.env.company diff --git a/sale_partner_company/readme/CONFIGURE.rst b/sale_partner_company/readme/CONFIGURE.rst new file mode 100644 index 00000000000..bb71810df5b --- /dev/null +++ b/sale_partner_company/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +On the partner, choose the default company. + +Create a sale.order with this partner, the sales company will be adapted from the partner. \ No newline at end of file diff --git a/sale_partner_company/readme/CONTRIBUTORS.rst b/sale_partner_company/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..cbfb628631d --- /dev/null +++ b/sale_partner_company/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ + * Telmo Santos + * Jacques-Etienne Baudoux (BCIM) diff --git a/sale_partner_company/readme/DESCRIPTION.rst b/sale_partner_company/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..943a1ca2eb3 --- /dev/null +++ b/sale_partner_company/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Allow to set the default selling company on a partner. \ No newline at end of file diff --git a/sale_partner_company/readme/USAGE.rst b/sale_partner_company/readme/USAGE.rst new file mode 100644 index 00000000000..ad6bdfd4ae9 --- /dev/null +++ b/sale_partner_company/readme/USAGE.rst @@ -0,0 +1 @@ +You need at least to manage 2 different companies. \ No newline at end of file diff --git a/sale_partner_company/static/description/index.html b/sale_partner_company/static/description/index.html new file mode 100644 index 00000000000..7d7477c3b6e --- /dev/null +++ b/sale_partner_company/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +sale partner companyy + + + +
+

sale partner companyy

+ + +

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

+

Allow to set the default selling company on a partner.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

On the partner, choose the default company.

+

Create a sale.order with this partner, the sales company will be adapted from the partner.

+
+
+

Usage

+

You need at least to manage 2 different companies.

+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
  • BCIM
  • +
+
+
+

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/sale_partner_company/tests/__init__.py b/sale_partner_company/tests/__init__.py new file mode 100644 index 00000000000..e5984ad6861 --- /dev/null +++ b/sale_partner_company/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_partner_company diff --git a/sale_partner_company/tests/test_sale_partner_company.py b/sale_partner_company/tests/test_sale_partner_company.py new file mode 100644 index 00000000000..b4f294ea3b9 --- /dev/null +++ b/sale_partner_company/tests/test_sale_partner_company.py @@ -0,0 +1,33 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import common +from odoo.tests.common import Form + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestSalePartnerCompany(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env["base"].with_context(**DISABLED_MAIL_CONTEXT).env + cls.company_1 = cls.env["res.company"].create({"name": "Test company 1"}) + + def test_sale_partner_company(self): + partner = self.env.ref("base.res_partner_12") + partner.sale_company_id = self.company_1 + + with Form(self.env["sale.order"]) as order_form: + order_form.partner_id = partner + self.order = order_form.save() + self.assertEqual(self.order.company_id, partner.sale_company_id) + + def test_sale_partner_company_with_default_partner(self): + partner = self.env.ref("base.res_partner_12") + partner.sale_company_id = self.company_1 + order_form = Form( + self.env["sale.order"].with_context(default_partner_id=partner.id) + ) + self.order = order_form.save() + self.assertEqual(self.order.company_id, partner.sale_company_id) diff --git a/sale_partner_company/views/partner_view.xml b/sale_partner_company/views/partner_view.xml new file mode 100644 index 00000000000..e1c052877e3 --- /dev/null +++ b/sale_partner_company/views/partner_view.xml @@ -0,0 +1,13 @@ + + + + res.partner.form.inherit + res.partner + + + + + + + + diff --git a/setup/sale_partner_company/odoo/addons/sale_partner_company b/setup/sale_partner_company/odoo/addons/sale_partner_company new file mode 120000 index 00000000000..b8b7b292a09 --- /dev/null +++ b/setup/sale_partner_company/odoo/addons/sale_partner_company @@ -0,0 +1 @@ +../../../../sale_partner_company \ No newline at end of file diff --git a/setup/sale_partner_company/setup.py b/setup/sale_partner_company/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_partner_company/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)