diff --git a/product_pricelist_margin/README.rst b/product_pricelist_margin/README.rst new file mode 100644 index 000000000000..dd61f1907c40 --- /dev/null +++ b/product_pricelist_margin/README.rst @@ -0,0 +1,86 @@ +======================== +Product Pricelist Margin +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f7a304e2acd01b42ff2f6e9de3dfa6a6ee4519e2beeddba42b49fad5e8d7d0b6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_margin + :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_margin + :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| + +This module shows the product's cost and margin from the pricelists. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to "Sale > Products > Pricelists" + +* Open a pricelist form + +* There are 3 new columns on the "Price rules" list. + .. image:: https://raw.githubusercontent.com/OCA/product-attribute/16.0/product_pricelist_margin/static/description/pricelist_item.png + +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 + +Contributors +~~~~~~~~~~~~ + +* Nguyen Minh Chien + +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/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_margin/__init__.py b/product_pricelist_margin/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/product_pricelist_margin/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_pricelist_margin/__manifest__.py b/product_pricelist_margin/__manifest__.py new file mode 100644 index 000000000000..f13efdc4913f --- /dev/null +++ b/product_pricelist_margin/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Product Pricelist Margin", + "summary": "This module shows the product's cost and margin from the pricelists.", + "version": "16.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["account"], + "data": [ + "views/product_pricelist_views.xml", + "views/product_pricelist_item_views.xml", + ], +} diff --git a/product_pricelist_margin/i18n/fr.pot b/product_pricelist_margin/i18n/fr.pot new file mode 100644 index 000000000000..7cd3d5a22bb9 --- /dev/null +++ b/product_pricelist_margin/i18n/fr.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_pricelist_margin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-03-20 08:44+0000\n" +"PO-Revision-Date: 2024-03-20 08:44+0000\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_pricelist_margin +#: model:ir.model.fields,field_description:product_pricelist_margin.field_product_pricelist_item__cost +msgid "Cost" +msgstr "Coût" + +#. module: product_pricelist_margin +#: model:ir.model.fields,help:product_pricelist_margin.field_product_pricelist_item__cost +msgid "" +"In Standard Price & AVCO: value of the product (automatically computed in AVCO).\n" +" In FIFO: value of the next unit that will leave the stock (automatically computed).\n" +" Used to value the product when the purchase cost is not known (e.g. inventory adjustment).\n" +" Used to compute margins on sale orders." +msgstr "" + +#. module: product_pricelist_margin +#: model:ir.model.fields,field_description:product_pricelist_margin.field_product_pricelist_item__margin +msgid "Margin" +msgstr "Marge" + +#. module: product_pricelist_margin +#: model:ir.model.fields,field_description:product_pricelist_margin.field_product_pricelist_item__margin_percent +msgid "Margin (%)" +msgstr "Marge (%)" + +#. module: product_pricelist_margin +#: model:ir.model,name:product_pricelist_margin.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Règle des listes des prix" diff --git a/product_pricelist_margin/i18n/product_pricelist_margins.pot b/product_pricelist_margin/i18n/product_pricelist_margins.pot new file mode 100644 index 000000000000..214ebb3b5250 --- /dev/null +++ b/product_pricelist_margin/i18n/product_pricelist_margins.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_pricelist_margin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-03-20 08:44+0000\n" +"PO-Revision-Date: 2024-03-20 08:44+0000\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_pricelist_margin +#: model:ir.model.fields,field_description:product_pricelist_margin.field_product_pricelist_item__cost +msgid "Cost" +msgstr "" + +#. module: product_pricelist_margin +#: model:ir.model.fields,help:product_pricelist_margin.field_product_pricelist_item__cost +msgid "" +"In Standard Price & AVCO: value of the product (automatically computed in AVCO).\n" +" In FIFO: value of the next unit that will leave the stock (automatically computed).\n" +" Used to value the product when the purchase cost is not known (e.g. inventory adjustment).\n" +" Used to compute margins on sale orders." +msgstr "" + +#. module: product_pricelist_margin +#: model:ir.model.fields,field_description:product_pricelist_margin.field_product_pricelist_item__margin +msgid "Margin" +msgstr "" + +#. module: product_pricelist_margin +#: model:ir.model.fields,field_description:product_pricelist_margin.field_product_pricelist_item__margin_percent +msgid "Margin (%)" +msgstr "" + +#. module: product_pricelist_margin +#: model:ir.model,name:product_pricelist_margin.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "" diff --git a/product_pricelist_margin/models/__init__.py b/product_pricelist_margin/models/__init__.py new file mode 100644 index 000000000000..41c51bd2f97a --- /dev/null +++ b/product_pricelist_margin/models/__init__.py @@ -0,0 +1 @@ +from . import product_pricelist_item diff --git a/product_pricelist_margin/models/product_pricelist_item.py b/product_pricelist_margin/models/product_pricelist_item.py new file mode 100644 index 000000000000..e0a0caf81f92 --- /dev/null +++ b/product_pricelist_margin/models/product_pricelist_item.py @@ -0,0 +1,71 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.tools.float_utils import float_is_zero + + +class ProductPricelistItem(models.Model): + _inherit = "product.pricelist.item" + + cost = fields.Float( + related="product_tmpl_id.standard_price", + digits="Product Price", + ) + margin = fields.Float( + compute="_compute_margin", + digits="Product Price", + ) + margin_percent = fields.Float( + string="Margin (%)", + compute="_compute_margin", + ) + + @api.depends( + "compute_price", + "applied_on", + "percent_price", + "base", + "price_discount", + "price_surcharge", + "price_round", + "price_min_margin", + "product_tmpl_id", + "cost", + "min_quantity", + "fixed_price", + ) + def _compute_margin(self): + for item in self: + if item.applied_on not in ("1_product", "0_product_variant"): + item.margin = 0 + item.margin_percent = 0 + continue + + price_rule = item.pricelist_id._compute_price_rule( + item.product_tmpl_id, item.min_quantity + ) + + price = price_rule.get(item.product_tmpl_id.id, [0])[0] + + if float_is_zero(price, precision_digits=item.currency_id.rounding): + item.margin = 0 + item.margin_percent = 0 + continue + + res = item.product_tmpl_id.taxes_id.compute_all( + price, + item.currency_id, + product=item.product_tmpl_id, + ) + + price_vat_excl = res["total_excluded"] + + cost = self.env.user.company_id.currency_id.compute( + item.cost, item.currency_id + ) + + item.margin = price_vat_excl - cost + item.margin_percent = ( + price_vat_excl and (item.margin / price_vat_excl) * 100 + ) diff --git a/product_pricelist_margin/readme/CONTRIBUTORS.rst b/product_pricelist_margin/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..9873004f8833 --- /dev/null +++ b/product_pricelist_margin/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Nguyen Minh Chien diff --git a/product_pricelist_margin/readme/DESCRIPTION.rst b/product_pricelist_margin/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..a3f5c0d0e473 --- /dev/null +++ b/product_pricelist_margin/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module shows the product's cost and margin from the pricelists. diff --git a/product_pricelist_margin/readme/USAGE.rst b/product_pricelist_margin/readme/USAGE.rst new file mode 100644 index 000000000000..315edf921964 --- /dev/null +++ b/product_pricelist_margin/readme/USAGE.rst @@ -0,0 +1,6 @@ +* Go to "Sale > Products > Pricelists" + +* Open a pricelist form + +* There are 3 new columns on the "Price rules" list. + .. image:: ../static/description/pricelist_item.png diff --git a/product_pricelist_margin/static/description/icon.png b/product_pricelist_margin/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/product_pricelist_margin/static/description/icon.png differ diff --git a/product_pricelist_margin/static/description/index.html b/product_pricelist_margin/static/description/index.html new file mode 100644 index 000000000000..92b86e060f73 --- /dev/null +++ b/product_pricelist_margin/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Product Pricelist Margin + + + +
+

Product Pricelist Margin

+ + +

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

+

This module shows the product’s cost and margin from the pricelists.

+

Table of contents

+ +
+

Usage

+ +
+
+

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
  • +
+
+
+

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/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_margin/static/description/pricelist_item.png b/product_pricelist_margin/static/description/pricelist_item.png new file mode 100644 index 000000000000..37898b5924c7 Binary files /dev/null and b/product_pricelist_margin/static/description/pricelist_item.png differ diff --git a/product_pricelist_margin/tests/__init__.py b/product_pricelist_margin/tests/__init__.py new file mode 100644 index 000000000000..26046ed2f70e --- /dev/null +++ b/product_pricelist_margin/tests/__init__.py @@ -0,0 +1 @@ +from . import test_margin diff --git a/product_pricelist_margin/tests/test_margin.py b/product_pricelist_margin/tests/test_margin.py new file mode 100644 index 000000000000..303ae3249a10 --- /dev/null +++ b/product_pricelist_margin/tests/test_margin.py @@ -0,0 +1,43 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import tagged + +from odoo.addons.base.tests.common import BaseCommon + + +@tagged("post_install", "-at_install") +class TestMargin(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env["product.product"].create( + { + "default_code": "pricelist-margin-product", + "name": "Demo Margin Product", + "list_price": 40.0, + "standard_price": 20.0, + } + ) + cls.pricelist = cls.env["product.pricelist"].create( + { + "name": "pricelist", + } + ) + + cls.line = cls.env["product.pricelist.item"].create( + { + "pricelist_id": cls.pricelist.id, + "product_tmpl_id": cls.product.product_tmpl_id.id, + "compute_price": "fixed", + "applied_on": "1_product", + "fixed_price": 35, + "min_quantity": 1, + } + ) + cls.env.ref("product.group_sale_pricelist").users |= cls.env.user + + def test_margin_computation_compute_price(self): + self.assertEqual(self.line.cost, 20.0) + self.assertEqual(self.line.margin, (35 - 20)) + self.assertEqual(self.line.margin_percent, ((35 - 20) / 35) * 100) diff --git a/product_pricelist_margin/views/product_pricelist_item_views.xml b/product_pricelist_margin/views/product_pricelist_item_views.xml new file mode 100644 index 000000000000..4064edf4a949 --- /dev/null +++ b/product_pricelist_margin/views/product_pricelist_item_views.xml @@ -0,0 +1,49 @@ + + + + + product.pricelist.item + + + + + + + + + + + product.pricelist.item + + + + + + + + + + + + + product.pricelist.item + + + + + + + + + + + + diff --git a/product_pricelist_margin/views/product_pricelist_views.xml b/product_pricelist_margin/views/product_pricelist_views.xml new file mode 100644 index 000000000000..cbf8765a93d4 --- /dev/null +++ b/product_pricelist_margin/views/product_pricelist_views.xml @@ -0,0 +1,43 @@ + + + + + product.pricelist + + + + + + + + + + + + + + + + diff --git a/setup/product_pricelist_margin/odoo/addons/product_pricelist_margin b/setup/product_pricelist_margin/odoo/addons/product_pricelist_margin new file mode 120000 index 000000000000..40ff82f0de42 --- /dev/null +++ b/setup/product_pricelist_margin/odoo/addons/product_pricelist_margin @@ -0,0 +1 @@ +../../../../product_pricelist_margin \ No newline at end of file diff --git a/setup/product_pricelist_margin/setup.py b/setup/product_pricelist_margin/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/product_pricelist_margin/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)