diff --git a/company_default_partner_pricelist/README.rst b/company_default_partner_pricelist/README.rst new file mode 100644 index 00000000000..7de1b497a7c --- /dev/null +++ b/company_default_partner_pricelist/README.rst @@ -0,0 +1,99 @@ +================================= +Company Default Partner Pricelist +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0f3bf1f33bb78d925a93f4930fc19d1354f4c7d93aa48a1450d46f1f4e181bd1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/16.0/company_default_partner_pricelist + :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-16-0/partner-contact-16-0-company_default_partner_pricelist + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +If the pricelist of a partner is not explicitly set, Odoo will try by default +to find a valid pricelist based on the country of the partner. + +This module allows assigning a default pricelist for each company in the system +to use as the default pricelist for partners. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To Configure the default company Pricelist: + +- Go to **General Settings** -> **Companies** +- Press the **"Update Info"** button +- On the Company form view, please select a pricelist for a company in the **"Default Account Pricelist"** field + +Usage +===== + +To use this module simply assign a default pricelist to the companies for +which you want to have a specific default value. + +If no default pricelist is assigned, the standard logic will apply. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow ` + + * Jordi Masvidal + +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/company_default_partner_pricelist/__init__.py b/company_default_partner_pricelist/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/company_default_partner_pricelist/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/company_default_partner_pricelist/__manifest__.py b/company_default_partner_pricelist/__manifest__.py new file mode 100644 index 00000000000..a0762c63115 --- /dev/null +++ b/company_default_partner_pricelist/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2023 ForgeFlow, S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Company Default Partner Pricelist", + "summary": """ + Define default partner pricelist per company. + """, + "version": "16.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/partner-contact", + "category": "Partner Management", + "depends": ["product"], + "data": ["views/res_company_views.xml"], + "installable": True, + "license": "LGPL-3", +} diff --git a/company_default_partner_pricelist/i18n/company_default_partner_pricelist.pot b/company_default_partner_pricelist/i18n/company_default_partner_pricelist.pot new file mode 100644 index 00000000000..dbbde0d33b5 --- /dev/null +++ b/company_default_partner_pricelist/i18n/company_default_partner_pricelist.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * company_default_partner_pricelist +# +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: company_default_partner_pricelist +#: model:ir.model,name:company_default_partner_pricelist.model_res_company +msgid "Companies" +msgstr "" + +#. module: company_default_partner_pricelist +#: model:ir.model.fields,field_description:company_default_partner_pricelist.field_res_company__default_property_product_pricelist_id +msgid "Default Account Pricelist" +msgstr "" + +#. module: company_default_partner_pricelist +#: model:ir.model.fields,help:company_default_partner_pricelist.field_res_company__default_property_product_pricelist_id +msgid "Default pricelist for this company for new partners." +msgstr "" diff --git a/company_default_partner_pricelist/models/__init__.py b/company_default_partner_pricelist/models/__init__.py new file mode 100644 index 00000000000..aff44f335ae --- /dev/null +++ b/company_default_partner_pricelist/models/__init__.py @@ -0,0 +1 @@ +from . import res_company diff --git a/company_default_partner_pricelist/models/res_company.py b/company_default_partner_pricelist/models/res_company.py new file mode 100644 index 00000000000..e48ea55742d --- /dev/null +++ b/company_default_partner_pricelist/models/res_company.py @@ -0,0 +1,59 @@ +# Copyright 2023 ForgeFlow, S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + default_property_product_pricelist_id = fields.Many2one( + "product.pricelist", + string="Default Account Pricelist", + help="Default pricelist for this company for new partners.", + ) + + def _update_partner_pricelist_generic_property(self): + self.ensure_one() + default_property_pp = self.default_property_product_pricelist_id + ir_property_obj = self.env["ir.property"].sudo() + field = self.env["ir.model.fields"]._get( + "res.partner", "property_product_pricelist" + ) + ppty = ir_property_obj.sudo().search( + [ + ("name", "=", "property_product_pricelist"), + ("company_id", "=", self.id), + ("fields_id", "=", field.id), + ("res_id", "=", False), + ], + limit=1, + ) + if ppty: + if not default_property_pp: + ppty.sudo().unlink() + else: + ppty.sudo().write( + {"value_reference": "product.pricelist,%s" % default_property_pp.id} + ) + elif default_property_pp: + ir_property_obj.sudo().create( + { + "name": "property_product_pricelist", + "value_reference": "product.pricelist,%s" % default_property_pp.id, + "fields_id": field.id, + "company_id": self.id, + } + ) + + def create(self, vals): + res = super(ResCompany, self).create(vals) + if "default_property_product_pricelist_id" in vals: + res._update_partner_pricelist_generic_property() + return res + + def write(self, vals): + res = super(ResCompany, self).write(vals) + if "default_property_product_pricelist_id" in vals: + for rec in self: + rec._update_partner_pricelist_generic_property() + return res diff --git a/company_default_partner_pricelist/readme/CONFIGURE.rst b/company_default_partner_pricelist/readme/CONFIGURE.rst new file mode 100644 index 00000000000..c6cc0941db8 --- /dev/null +++ b/company_default_partner_pricelist/readme/CONFIGURE.rst @@ -0,0 +1,5 @@ +To Configure the default company Pricelist: + +- Go to **General Settings** -> **Companies** +- Press the **"Update Info"** button +- On the Company form view, please select a pricelist for a company in the **"Default Account Pricelist"** field diff --git a/company_default_partner_pricelist/readme/CONTRIBUTORS.rst b/company_default_partner_pricelist/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..54d2fc89bd7 --- /dev/null +++ b/company_default_partner_pricelist/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow ` + + * Jordi Masvidal diff --git a/company_default_partner_pricelist/readme/DESCRIPTION.rst b/company_default_partner_pricelist/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..cf65c2df473 --- /dev/null +++ b/company_default_partner_pricelist/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +If the pricelist of a partner is not explicitly set, Odoo will try by default +to find a valid pricelist based on the country of the partner. + +This module allows assigning a default pricelist for each company in the system +to use as the default pricelist for partners. diff --git a/company_default_partner_pricelist/readme/USAGE.rst b/company_default_partner_pricelist/readme/USAGE.rst new file mode 100644 index 00000000000..5f5e794f77b --- /dev/null +++ b/company_default_partner_pricelist/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module simply assign a default pricelist to the companies for +which you want to have a specific default value. + +If no default pricelist is assigned, the standard logic will apply. diff --git a/company_default_partner_pricelist/static/description/icon.png b/company_default_partner_pricelist/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/company_default_partner_pricelist/static/description/icon.png differ diff --git a/company_default_partner_pricelist/static/description/index.html b/company_default_partner_pricelist/static/description/index.html new file mode 100644 index 00000000000..a5ca94831c6 --- /dev/null +++ b/company_default_partner_pricelist/static/description/index.html @@ -0,0 +1,443 @@ + + + + + +Company Default Partner Pricelist + + + +
+

Company Default Partner Pricelist

+ + +

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

+

If the pricelist of a partner is not explicitly set, Odoo will try by default +to find a valid pricelist based on the country of the partner.

+

This module allows assigning a default pricelist for each company in the system +to use as the default pricelist for partners.

+

Table of contents

+ +
+

Configuration

+

To Configure the default company Pricelist:

+
    +
  • Go to General Settings -> Companies
  • +
  • Press the “Update Info” button
  • +
  • On the Company form view, please select a pricelist for a company in the “Default Account Pricelist” field
  • +
+
+
+

Usage

+

To use this module simply assign a default pricelist to the companies for +which you want to have a specific default value.

+

If no default pricelist is assigned, the standard logic will apply.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+
    +
  • ForgeFlow <https://www.forgeflow.com>
      +
    • Jordi Masvidal
    • +
    +
  • +
+
+
+

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/company_default_partner_pricelist/tests/__init__.py b/company_default_partner_pricelist/tests/__init__.py new file mode 100644 index 00000000000..629be01cab5 --- /dev/null +++ b/company_default_partner_pricelist/tests/__init__.py @@ -0,0 +1 @@ +from . import test_company_default_partner_pricelist diff --git a/company_default_partner_pricelist/tests/test_company_default_partner_pricelist.py b/company_default_partner_pricelist/tests/test_company_default_partner_pricelist.py new file mode 100644 index 00000000000..f4ecdfecf0a --- /dev/null +++ b/company_default_partner_pricelist/tests/test_company_default_partner_pricelist.py @@ -0,0 +1,43 @@ +# Copyright 2023 ForgeFlow, S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.tests import common + + +class TestCompanyDefaultPartnerPricelist(common.TransactionCase): + def setUp(self): + super().setUp() + self.base_pricelist = self.env.ref("product.list0") + self.pricelist_1 = self.env["product.pricelist"].create( + {"name": "Test pricelist 1"} + ) + self.pricelist_2 = self.env["product.pricelist"].create( + {"name": "Test pricelist 2"} + ) + self.pricelist_3 = self.env["product.pricelist"].create( + {"name": "Test pricelist 3"} + ) + self.partner = self.env["res.partner"].create({"name": "Test customer"}) + + def test_company_default_partner_pricelist(self): + """Test Company Default Partner Pricelist""" + # By default, the pricelist of the partner is the first valid pricelist + self.assertEqual(self.partner.property_product_pricelist, self.base_pricelist) + # When the default is changed for the active company, the pricelist of + # the partner is the one assigned to the current company + self.env.company.default_property_product_pricelist_id = self.pricelist_2 + self.partner.invalidate_recordset() + self.assertEqual(self.partner.property_product_pricelist, self.pricelist_2) + + self.env.company.default_property_product_pricelist_id = self.pricelist_3 + self.partner.invalidate_recordset() + self.assertEqual(self.partner.property_product_pricelist, self.pricelist_3) + + self.env.company.default_property_product_pricelist_id = False + self.partner.invalidate_recordset() + self.assertEqual(self.partner.property_product_pricelist, self.base_pricelist) + + # Finally, when modified explicitly, the pricelist is the one + # set by the user + self.partner.property_product_pricelist = self.pricelist_1 + self.assertEqual(self.partner.property_product_pricelist, self.pricelist_1) diff --git a/company_default_partner_pricelist/views/res_company_views.xml b/company_default_partner_pricelist/views/res_company_views.xml new file mode 100644 index 00000000000..117ef66c123 --- /dev/null +++ b/company_default_partner_pricelist/views/res_company_views.xml @@ -0,0 +1,30 @@ + + + + res.company.tree - company_default_partner_pricelist + res.company + + + + + + + + + res.company.form - company_default_partner_pricelist + res.company + + + + + + + + diff --git a/setup/company_default_partner_pricelist/odoo/addons/company_default_partner_pricelist b/setup/company_default_partner_pricelist/odoo/addons/company_default_partner_pricelist new file mode 120000 index 00000000000..fba18a00c33 --- /dev/null +++ b/setup/company_default_partner_pricelist/odoo/addons/company_default_partner_pricelist @@ -0,0 +1 @@ +../../../../company_default_partner_pricelist \ No newline at end of file diff --git a/setup/company_default_partner_pricelist/setup.py b/setup/company_default_partner_pricelist/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/company_default_partner_pricelist/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)