diff --git a/product_pricelist_company_price/README.rst b/product_pricelist_company_price/README.rst new file mode 100644 index 00000000000..50701300311 --- /dev/null +++ b/product_pricelist_company_price/README.rst @@ -0,0 +1,98 @@ +============================ +Price from company pricelist +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d87e22e76f34eb418645d0b21645c1c8a3071e03cb21d7a80ffe1253b9af6167 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_company_price + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_pricelist_company_price + :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/product-attribute&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Manage product prices from a pricelist configured at company level. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Enable Advanced Pricelists and fill the Products pricelist in General Settings. + +Usage +===== + +In the configured pricelist, define product or variant rules computed with fixed price. + +The chosen products will have their sale price set to the price fixed in the pricelist. + +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 +~~~~~~~ + +* Aion Tech + +Contributors +~~~~~~~~~~~~ + +* `Aion Tech `_: + + * Simone Rubino + +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. + +.. |maintainer-SirAionTech| image:: https://github.com/SirAionTech.png?size=40px + :target: https://github.com/SirAionTech + :alt: SirAionTech + +Current `maintainer `__: + +|maintainer-SirAionTech| + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_pricelist_company_price/__init__.py b/product_pricelist_company_price/__init__.py new file mode 100644 index 00000000000..b18eea37960 --- /dev/null +++ b/product_pricelist_company_price/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/product_pricelist_company_price/__manifest__.py b/product_pricelist_company_price/__manifest__.py new file mode 100644 index 00000000000..b1986500c27 --- /dev/null +++ b/product_pricelist_company_price/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Price from company pricelist", + "summary": "Manage product prices from a pricelist configured at company level.", + "version": "16.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/product-attribute" + "/tree/16.0/product_pricelist_company_price", + "author": "Aion Tech, Odoo Community Association (OCA)", + "maintainers": [ + "SirAionTech", + ], + "license": "AGPL-3", + "depends": [ + "product", + ], + "data": [ + "views/product_template_views.xml", + "views/product_product_views.xml", + "views/res_config_settings_views.xml", + ], +} diff --git a/product_pricelist_company_price/i18n/it.po b/product_pricelist_company_price/i18n/it.po new file mode 100644 index 00000000000..24ee663d309 --- /dev/null +++ b/product_pricelist_company_price/i18n/it.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_pricelist_company_price +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-23 11:42+0000\n" +"PO-Revision-Date: 2023-11-23 11:42+0000\n" +"Last-Translator: Simone Rubino \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_pricelist_company_price +#: model:ir.model,name:product_pricelist_company_price.model_res_company +msgid "Companies" +msgstr "Aziende" + +#. module: product_pricelist_company_price +#: model:ir.model,name:product_pricelist_company_price.model_res_config_settings +msgid "Config Settings" +msgstr "Impostazioni di configurazione" + +#. module: product_pricelist_company_price +#: model:ir.model,name:product_pricelist_company_price.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Regola listino prezzi" + +#. module: product_pricelist_company_price +#: model:ir.model.fields,help:product_pricelist_company_price.field_res_company__products_price_pricelist_id +#: model:ir.model.fields,help:product_pricelist_company_price.field_res_config_settings__products_price_pricelist_id +#: model_terms:ir.ui.view,arch_db:product_pricelist_company_price.res_config_settings_view_form +msgid "" +"Prices set for individual products in this pricelist propagate to the sales " +"price of the products it affects." +msgstr "" +"I prezzi impostato per i singoli prodotti in questo listino saranno riportati " +"sui prezzi di vendita dei prodotti interessati." + +#. module: product_pricelist_company_price +#: model:ir.model,name:product_pricelist_company_price.model_product_template +msgid "Product" +msgstr "Prodotto" + +#. module: product_pricelist_company_price +#: model:ir.model,name:product_pricelist_company_price.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#. module: product_pricelist_company_price +#: model:ir.model.fields,field_description:product_pricelist_company_price.field_res_company__products_price_pricelist_id +#: model:ir.model.fields,field_description:product_pricelist_company_price.field_res_config_settings__products_price_pricelist_id +#: model_terms:ir.ui.view,arch_db:product_pricelist_company_price.res_config_settings_view_form +msgid "Products Pricelist" +msgstr "Listino prodotti" diff --git a/product_pricelist_company_price/models/__init__.py b/product_pricelist_company_price/models/__init__.py new file mode 100644 index 00000000000..72b56143c24 --- /dev/null +++ b/product_pricelist_company_price/models/__init__.py @@ -0,0 +1,7 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import product_pricelist_item +from . import product_product +from . import product_template +from . import res_company +from . import res_config_settings diff --git a/product_pricelist_company_price/models/product_pricelist_item.py b/product_pricelist_company_price/models/product_pricelist_item.py new file mode 100644 index 00000000000..70478c0a750 --- /dev/null +++ b/product_pricelist_company_price/models/product_pricelist_item.py @@ -0,0 +1,44 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProductPricelistItem(models.Model): + _inherit = "product.pricelist.item" + + def _is_products_pricelist_item(self): + """This price rule will update product prices when updated.""" + self.ensure_one() + company = self.company_id or self.env.company + company_pricelist = company.products_price_pricelist_id + return ( + self.pricelist_id == company_pricelist + and self.compute_price == "fixed" + and self.applied_on + in [ + "1_product", + "0_product_variant", + ] + ) + + def _update_products_pricelist_prices(self): + """If the items are in the company pricelist, update price of matching products.""" + for item in self: + if item._is_products_pricelist_item(): + price = item.fixed_price + if item.applied_on == "1_product": + item.product_tmpl_id.list_price = price + elif item.applied_on == "0_product_variant": + item.product_id.lst_price = price + + @api.model_create_multi + def create(self, vals_list): + items = super().create(vals_list) + items._update_products_pricelist_prices() + return items + + def write(self, vals): + res = super().write(vals) + self._update_products_pricelist_prices() + return res diff --git a/product_pricelist_company_price/models/product_product.py b/product_pricelist_company_price/models/product_product.py new file mode 100644 index 00000000000..075dc8841f4 --- /dev/null +++ b/product_pricelist_company_price/models/product_product.py @@ -0,0 +1,35 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + is_in_products_pricelist = fields.Boolean( + compute="_compute_is_in_products_pricelist", + ) + + @api.model + def _is_in_products_pricelist(self, product): + """Determine if `product` (template or variant) is in the Company pricelist.""" + now = fields.Datetime.now() + company = product.company_id or product.env.company + products_pricelist = company.products_price_pricelist_id + if products_pricelist: + products_pricelist_items = products_pricelist._get_applicable_rules( + product, now + ) + products_pricelist_items = products_pricelist_items.filtered( + lambda rule: rule._is_products_pricelist_item() + ) + is_in_products_pricelist = bool(products_pricelist_items) + else: + is_in_products_pricelist = False + return is_in_products_pricelist + + def _compute_is_in_products_pricelist(self): + for product in self: + is_in_products_pricelist = self._is_in_products_pricelist(product) + product.is_in_products_pricelist = is_in_products_pricelist diff --git a/product_pricelist_company_price/models/product_template.py b/product_pricelist_company_price/models/product_template.py new file mode 100644 index 00000000000..819770e6951 --- /dev/null +++ b/product_pricelist_company_price/models/product_template.py @@ -0,0 +1,18 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + is_in_products_pricelist = fields.Boolean( + compute="_compute_is_in_products_pricelist", + ) + + def _compute_is_in_products_pricelist(self): + product_model = self.env["product.product"] + for product in self: + is_in_products_pricelist = product_model._is_in_products_pricelist(product) + product.is_in_products_pricelist = is_in_products_pricelist diff --git a/product_pricelist_company_price/models/res_company.py b/product_pricelist_company_price/models/res_company.py new file mode 100644 index 00000000000..d5b604bac6f --- /dev/null +++ b/product_pricelist_company_price/models/res_company.py @@ -0,0 +1,24 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + products_price_pricelist_id = fields.Many2one( + comodel_name="product.pricelist", + string="Products Pricelist", + help="Prices set for individual products in this pricelist " + "propagate to the sales price of the products it affects.", + ) + + def write(self, vals): + res = super().write(vals) + if "products_price_pricelist_id" in vals: + for company in self: + products_pricelist = company.products_price_pricelist_id + if products_pricelist: + products_pricelist.item_ids._update_products_pricelist_prices() + return res diff --git a/product_pricelist_company_price/models/res_config_settings.py b/product_pricelist_company_price/models/res_config_settings.py new file mode 100644 index 00000000000..3267ce1bd26 --- /dev/null +++ b/product_pricelist_company_price/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + products_price_pricelist_id = fields.Many2one( + related="company_id.products_price_pricelist_id", + readonly=False, + ) diff --git a/product_pricelist_company_price/readme/CONFIGURE.rst b/product_pricelist_company_price/readme/CONFIGURE.rst new file mode 100644 index 00000000000..350863f1dc2 --- /dev/null +++ b/product_pricelist_company_price/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Enable Advanced Pricelists and fill the Products pricelist in General Settings. diff --git a/product_pricelist_company_price/readme/CONTRIBUTORS.rst b/product_pricelist_company_price/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..6afa1541b48 --- /dev/null +++ b/product_pricelist_company_price/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Aion Tech `_: + + * Simone Rubino diff --git a/product_pricelist_company_price/readme/DESCRIPTION.rst b/product_pricelist_company_price/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..d252fd70f2a --- /dev/null +++ b/product_pricelist_company_price/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Manage product prices from a pricelist configured at company level. diff --git a/product_pricelist_company_price/readme/USAGE.rst b/product_pricelist_company_price/readme/USAGE.rst new file mode 100644 index 00000000000..d90c9a8ecc8 --- /dev/null +++ b/product_pricelist_company_price/readme/USAGE.rst @@ -0,0 +1,3 @@ +In the configured pricelist, define product or variant rules computed with fixed price. + +The chosen products will have their sale price set to the price fixed in the pricelist. diff --git a/product_pricelist_company_price/static/description/index.html b/product_pricelist_company_price/static/description/index.html new file mode 100644 index 00000000000..933ea6f8213 --- /dev/null +++ b/product_pricelist_company_price/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +Price from company pricelist + + + +
+

Price from company pricelist

+ + +

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

+

Manage product prices from a pricelist configured at company level.

+

Table of contents

+ +
+

Configuration

+

Enable Advanced Pricelists and fill the Products pricelist in General Settings.

+
+
+

Usage

+

In the configured pricelist, define product or variant rules computed with fixed price.

+

The chosen products will have their sale price set to the price fixed in the pricelist.

+
+
+

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

+
    +
  • Aion Tech
  • +
+
+
+

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.

+

Current maintainer:

+

SirAionTech

+

This module is part of the OCA/product-attribute project on GitHub.

+

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

+
+
+
+ + diff --git a/product_pricelist_company_price/tests/__init__.py b/product_pricelist_company_price/tests/__init__.py new file mode 100644 index 00000000000..2793fe418d3 --- /dev/null +++ b/product_pricelist_company_price/tests/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_company +from . import test_pricelist diff --git a/product_pricelist_company_price/tests/common.py b/product_pricelist_company_price/tests/common.py new file mode 100644 index 00000000000..84c98f34045 --- /dev/null +++ b/product_pricelist_company_price/tests/common.py @@ -0,0 +1,46 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import TransactionCase + + +class Common(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.company + cls.product = cls.env["product.product"].create( + { + "name": "Product", + "lst_price": 100, + } + ) + cls.pricelist = cls.env["product.pricelist"].create( + { + "name": "Pricelist", + } + ) + cls.company.products_price_pricelist_id = cls.pricelist + + def _create_item(self, pricelist, product, price): + item_values = { + "pricelist_id": pricelist.id, + "compute_price": "fixed", + "fixed_price": price, + } + if product._name == "product.product": + item_values.update( + { + "applied_on": "0_product_variant", + "product_id": product.id, + } + ) + elif product._name == "product.template": + item_values.update( + { + "applied_on": "1_product", + "product_tmpl_id": product.id, + } + ) + item = self.env["product.pricelist.item"].create(item_values) + return item diff --git a/product_pricelist_company_price/tests/test_company.py b/product_pricelist_company_price/tests/test_company.py new file mode 100644 index 00000000000..8fb7ce533a5 --- /dev/null +++ b/product_pricelist_company_price/tests/test_company.py @@ -0,0 +1,34 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from .common import Common + + +class TestCompany(Common): + def test_set_pricelist(self): + """Set a pricelist in the company, + the products prices are applied.""" + # Arrange + company = self.company + company.products_price_pricelist_id = False + pricelist = self.pricelist + product = self.product + self._create_item(pricelist, product, 10) + # pre-condition + self.assertEqual(product.lst_price, 100) + self.assertFalse(product.is_in_products_pricelist) + + # Act + company.products_price_pricelist_id = pricelist + + # Assert + self.assertEqual(product.lst_price, 10) + self.assertFalse( + product.is_in_products_pricelist, "No need to invalidate the cache" + ) + product.invalidate_recordset( + fnames=[ + "is_in_products_pricelist", + ], + ) + self.assertTrue(product.is_in_products_pricelist) diff --git a/product_pricelist_company_price/tests/test_pricelist.py b/product_pricelist_company_price/tests/test_pricelist.py new file mode 100644 index 00000000000..e15638b77f5 --- /dev/null +++ b/product_pricelist_company_price/tests/test_pricelist.py @@ -0,0 +1,79 @@ +# Copyright 2023 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from .common import Common + + +class TestPricelist(Common): + def test_create_rule(self): + """Create a rule for a product, + the product's price is updated.""" + # Arrange + company = self.company + product = self.product + pricelist = company.products_price_pricelist_id + # pre-condition + self.assertEqual(product.lst_price, 100) + self.assertFalse(product.is_in_products_pricelist) + + # Act + fixed_price = 10 + self._create_item(pricelist, product, fixed_price) + + # Assert + self.assertEqual(product.lst_price, fixed_price) + self.assertFalse( + product.is_in_products_pricelist, "No need to invalidate the cache" + ) + product.invalidate_recordset( + fnames=[ + "is_in_products_pricelist", + ], + ) + self.assertTrue(product.is_in_products_pricelist) + + def test_create_template_rule(self): + """Create a rule for a product template, + the product's price is updated.""" + # Arrange + company = self.company + product = self.product.product_tmpl_id + pricelist = company.products_price_pricelist_id + # pre-condition + self.assertEqual(product.list_price, 100) + self.assertFalse(product.is_in_products_pricelist) + + # Act + fixed_price = 10 + self._create_item(pricelist, product, fixed_price) + + # Assert + self.assertEqual(product.list_price, fixed_price) + self.assertFalse( + product.is_in_products_pricelist, "No need to invalidate the cache" + ) + product.invalidate_recordset( + fnames=[ + "is_in_products_pricelist", + ], + ) + self.assertTrue(product.is_in_products_pricelist) + + def test_update_rule(self): + """Update a rule for a product, + the product's price is updated.""" + # Arrange + company = self.company + product = self.product + pricelist = company.products_price_pricelist_id + item = self._create_item(pricelist, product, 10) + # pre-condition + self.assertEqual(product.lst_price, 10) + self.assertTrue(product.is_in_products_pricelist) + + # Act + fixed_price = 20 + item.fixed_price = fixed_price + + # Assert + self.assertEqual(product.lst_price, fixed_price) diff --git a/product_pricelist_company_price/views/product_product_views.xml b/product_pricelist_company_price/views/product_product_views.xml new file mode 100644 index 00000000000..981b4255d79 --- /dev/null +++ b/product_pricelist_company_price/views/product_product_views.xml @@ -0,0 +1,23 @@ + + + + + Add company pricelist fields to variant form view + product.product + + + + + { + "readonly": [ + ("is_in_products_pricelist", "=", True), + ], + } + + + + + diff --git a/product_pricelist_company_price/views/product_template_views.xml b/product_pricelist_company_price/views/product_template_views.xml new file mode 100644 index 00000000000..036cb2d9721 --- /dev/null +++ b/product_pricelist_company_price/views/product_template_views.xml @@ -0,0 +1,26 @@ + + + + + Add products pricelist fields to product form view + product.template + + + + + + + + { + "readonly": [ + ("is_in_products_pricelist", "=", True), + ], + } + + + + + diff --git a/product_pricelist_company_price/views/res_config_settings_views.xml b/product_pricelist_company_price/views/res_config_settings_views.xml new file mode 100644 index 00000000000..ffe0fc43ae0 --- /dev/null +++ b/product_pricelist_company_price/views/res_config_settings_views.xml @@ -0,0 +1,36 @@ + + + + + Add company pricelist fields to product settings + res.config.settings + + + +
+
+
+
+
+
+
+
diff --git a/setup/product_pricelist_company_price/odoo/addons/product_pricelist_company_price b/setup/product_pricelist_company_price/odoo/addons/product_pricelist_company_price new file mode 120000 index 00000000000..3e004d81ca5 --- /dev/null +++ b/setup/product_pricelist_company_price/odoo/addons/product_pricelist_company_price @@ -0,0 +1 @@ +../../../../product_pricelist_company_price \ No newline at end of file diff --git a/setup/product_pricelist_company_price/setup.py b/setup/product_pricelist_company_price/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/product_pricelist_company_price/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)