diff --git a/sale_elaboration_margin/README.rst b/sale_elaboration_margin/README.rst new file mode 100644 index 000000000..71e82877e --- /dev/null +++ b/sale_elaboration_margin/README.rst @@ -0,0 +1,97 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================= +Sale Elaboration Margin +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:485c92d8fb4cce354e556411e031f431d9c1589f6dfb17229f8a40d3fe14d835 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/license-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%2Fmargin--analysis-lightgray.png?logo=github + :target: https://github.com/OCA/margin-analysis/tree/19.0/sale_elaboration_margin + :alt: OCA/margin-analysis +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/margin-analysis-19-0/margin-analysis-19-0-sale_elaboration_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/margin-analysis&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of sale_elaboration module to +allow to display margin data from elaboration costs. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Sale > Orders > Quotations*. +2. Create a sales order. +3. Add a new line. +4. Select an elaboration in the line. +5. Confirm the sales order. +6. Go to the picking created by this sales order and validate it. +7. Go back to the sales order. A new line is created with the product + linked to the elaboration. + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Sergio Teruel + - Pedro M. Baeza + - Carlos Roca + +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/margin-analysis `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_elaboration_margin/__init__.py b/sale_elaboration_margin/__init__.py new file mode 100644 index 000000000..3275ac2ad --- /dev/null +++ b/sale_elaboration_margin/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/sale_elaboration_margin/__manifest__.py b/sale_elaboration_margin/__manifest__.py new file mode 100644 index 000000000..f9510b02f --- /dev/null +++ b/sale_elaboration_margin/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2021 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Elaboration Margin", + "summary": "Compute elaboration margins in sale orders lines", + "version": "19.0.1.0.0", + "development_status": "Production/Stable", + "category": "Sale", + "website": "https://github.com/OCA/margin-analysis", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["sale_elaboration"], + "data": ["views/sale_order_views.xml"], +} diff --git a/sale_elaboration_margin/i18n/es.po b/sale_elaboration_margin/i18n/es.po new file mode 100644 index 000000000..491cb3e28 --- /dev/null +++ b/sale_elaboration_margin/i18n/es.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_elaboration_margin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-12-20 09:22+0000\n" +"PO-Revision-Date: 2019-12-20 10:23+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_cost_price +msgid "Elaboration Cost" +msgstr "Coste elaboración" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_margin +msgid "Elaboration Margin" +msgstr "Margen elaboración" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_price +msgid "Elaboration Price" +msgstr "Precio elaboración" + +#. module: sale_elaboration_margin +#: model:ir.model,name:sale_elaboration_margin.model_sale_order_line +msgid "Sales Order Line" +msgstr "Líneas de pedido" diff --git a/sale_elaboration_margin/i18n/it.po b/sale_elaboration_margin/i18n/it.po new file mode 100644 index 000000000..841d6dfce --- /dev/null +++ b/sale_elaboration_margin/i18n/it.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_elaboration_margin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-04-13 10:35+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 5.15.2\n" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_cost_price +msgid "Elaboration Cost" +msgstr "Costo elaborazione" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_margin +msgid "Elaboration Margin" +msgstr "Margine elaborazione" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_price +msgid "Elaboration Price" +msgstr "Prezzo elaborazione" + +#. module: sale_elaboration_margin +#: model:ir.model,name:sale_elaboration_margin.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" diff --git a/sale_elaboration_margin/i18n/sale_elaboration_margin.pot b/sale_elaboration_margin/i18n/sale_elaboration_margin.pot new file mode 100644 index 000000000..07faca324 --- /dev/null +++ b/sale_elaboration_margin/i18n/sale_elaboration_margin.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_elaboration_margin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.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_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_cost_price +msgid "Elaboration Cost" +msgstr "" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_margin +msgid "Elaboration Margin" +msgstr "" + +#. module: sale_elaboration_margin +#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_price +msgid "Elaboration Price" +msgstr "" + +#. module: sale_elaboration_margin +#: model:ir.model,name:sale_elaboration_margin.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/sale_elaboration_margin/models/__init__.py b/sale_elaboration_margin/models/__init__.py new file mode 100644 index 000000000..49fac809e --- /dev/null +++ b/sale_elaboration_margin/models/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import sale_order diff --git a/sale_elaboration_margin/models/sale_order.py b/sale_elaboration_margin/models/sale_order.py new file mode 100644 index 000000000..0eb31de69 --- /dev/null +++ b/sale_elaboration_margin/models/sale_order.py @@ -0,0 +1,71 @@ +# Copyright 2021 Tecnativa - Sergio Teruel +# Copyright 2021 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + elaboration_cost_price = fields.Float( + compute="_compute_elaboration_price", + store=True, + readonly=False, + string="Elaboration Cost", + digits="Product Price", + aggregator="avg", + ) + elaboration_price = fields.Float( + compute="_compute_elaboration_price", + store=True, + readonly=False, + digits="Product Price", + aggregator="avg", + ) + elaboration_margin = fields.Monetary( + compute="_compute_elaboration_margin", + currency_field="currency_id", + default=0.0, + ) + + @api.depends("elaboration_ids") + def _compute_elaboration_price(self): + for line in self: + if not line.elaboration_ids: + line.elaboration_cost_price = 0.0 + line.elaboration_price = 0.0 + elif line.order_id.pricelist_id and line.order_id.partner_id: + elaboration_price = 0 + elaboration_cost_price = 0 + for elaboration_product in line.elaboration_ids.product_id: + new_sol = self.env["sale.order.line"].new( + { + "order_id": line.order_id.id, + "product_id": elaboration_product.id, + "product_uom_qty": line.product_uom_qty, + "product_uom_id": line.product_uom_id.id, + "sequence": max( + line.order_id.order_line.mapped("sequence"), default=0 + ) + + 1, + } + ) + new_sol._compute_price_unit() + elaboration_price += self.env[ + "account.tax" + ]._fix_tax_included_price_company( + new_sol.price_unit, + elaboration_product.taxes_id, + line.tax_ids, + line.company_id, + ) + new_sol.order_id = False + elaboration_cost_price += elaboration_product.standard_price + line.elaboration_price = elaboration_price + line.elaboration_cost_price = elaboration_cost_price + + def _compute_elaboration_margin(self): + for line in self: + line.elaboration_margin = (line.qty_delivered or line.product_uom_qty) * ( + line.elaboration_price - line.elaboration_cost_price + ) diff --git a/sale_elaboration_margin/pyproject.toml b/sale_elaboration_margin/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/sale_elaboration_margin/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_elaboration_margin/readme/CONTRIBUTORS.md b/sale_elaboration_margin/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..bb68b91de --- /dev/null +++ b/sale_elaboration_margin/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel + - Pedro M. Baeza + - Carlos Roca diff --git a/sale_elaboration_margin/readme/DESCRIPTION.md b/sale_elaboration_margin/readme/DESCRIPTION.md new file mode 100644 index 000000000..4014a2a96 --- /dev/null +++ b/sale_elaboration_margin/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends the functionality of sale_elaboration module to +allow to display margin data from elaboration costs. diff --git a/sale_elaboration_margin/readme/USAGE.md b/sale_elaboration_margin/readme/USAGE.md new file mode 100644 index 000000000..4cadfa33c --- /dev/null +++ b/sale_elaboration_margin/readme/USAGE.md @@ -0,0 +1,8 @@ +1. Go to *Sale \> Orders \> Quotations*. +2. Create a sales order. +3. Add a new line. +4. Select an elaboration in the line. +5. Confirm the sales order. +6. Go to the picking created by this sales order and validate it. +7. Go back to the sales order. A new line is created with the product + linked to the elaboration. diff --git a/sale_elaboration_margin/static/description/icon.png b/sale_elaboration_margin/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sale_elaboration_margin/static/description/icon.png differ diff --git a/sale_elaboration_margin/static/description/index.html b/sale_elaboration_margin/static/description/index.html new file mode 100644 index 000000000..a4132701c --- /dev/null +++ b/sale_elaboration_margin/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Elaboration Margin

+ +

Production/Stable License: AGPL-3 OCA/margin-analysis Translate me on Weblate Try me on Runboat

+

This module extends the functionality of sale_elaboration module to +allow to display margin data from elaboration costs.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Sale > Orders > Quotations.
  2. +
  3. Create a sales order.
  4. +
  5. Add a new line.
  6. +
  7. Select an elaboration in the line.
  8. +
  9. Confirm the sales order.
  10. +
  11. Go to the picking created by this sales order and validate it.
  12. +
  13. Go back to the sales order. A new line is created with the product +linked to the elaboration.
  14. +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Sergio Teruel
    • +
    • Pedro M. Baeza
    • +
    • Carlos Roca
    • +
    +
  • +
+
+
+

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/margin-analysis project on GitHub.

+

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

+
+
+
+
+ + diff --git a/sale_elaboration_margin/tests/__init__.py b/sale_elaboration_margin/tests/__init__.py new file mode 100644 index 000000000..339476610 --- /dev/null +++ b/sale_elaboration_margin/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_elaboration_margin diff --git a/sale_elaboration_margin/tests/test_sale_elaboration_margin.py b/sale_elaboration_margin/tests/test_sale_elaboration_margin.py new file mode 100644 index 000000000..646e8b7a1 --- /dev/null +++ b/sale_elaboration_margin/tests/test_sale_elaboration_margin.py @@ -0,0 +1,108 @@ +from odoo.tests.common import TransactionCase + + +class TestSaleElaborationMargin(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.company = cls.env.company + + # Setup Pricelist + cls.pricelist = cls.env["product.pricelist"].create( + { + "name": "Test Pricelist", + "currency_id": cls.company.currency_id.id, + } + ) + + # Setup Partner + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + "property_product_pricelist": cls.pricelist.id, + } + ) + + # Setup Product + cls.product = cls.env["product.product"].create( + { + "name": "Test Product", + "type": "consu", + "list_price": 100.0, + } + ) + + # Setup Elaboration Product + cls.elaboration_product = cls.env["product.product"].create( + { + "name": "Test Elaboration", + "type": "service", + "list_price": 20.0, + "standard_price": 15.0, + } + ) + + # Add taxes to the elaboration product to cover tax compute block + cls.tax = cls.env["account.tax"].create( + { + "name": "Test Tax 10%", + "amount_type": "percent", + "amount": 10.0, + "price_include_override": "tax_included", + } + ) + cls.elaboration_product.taxes_id = [(6, 0, cls.tax.ids)] + + # Setup Sale Order + cls.sale_order = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "pricelist_id": cls.pricelist.id, + } + ) + + # Setup Sale Order Line + cls.sale_line = cls.env["sale.order.line"].create( + { + "order_id": cls.sale_order.id, + "product_id": cls.product.id, + "product_uom_qty": 2.0, + "price_unit": 100.0, + } + ) + + def test_sale_elaboration_margin(self): + # Initial check with no elaboration + self.sale_line._compute_elaboration_price() + self.assertEqual(self.sale_line.elaboration_price, 0.0) + self.assertEqual(self.sale_line.elaboration_cost_price, 0.0) + + elaboration = self.env["product.elaboration"].create( + { + "name": "Test Elaboration Profile", + "product_id": self.elaboration_product.id, + } + ) + self.sale_line.write({"elaboration_ids": [(4, elaboration.id)]}) + + self.sale_line._compute_elaboration_price() + + # Elaboration price should be the price of the elaboration + # product from the pricelist, minus included taxes. + + self.assertTrue(self.sale_line.elaboration_price > 0.0) + + # Elaboration cost price should be standard_price * 1 + # (because the compute loop adds it directly per elaboration product) + + self.assertEqual(self.sale_line.elaboration_cost_price, 15.0) + + # Test margin computation + self.sale_line._compute_elaboration_margin() + + # Qty is 2.0 + expected_margin = 2.0 * ( + self.sale_line.elaboration_price - self.sale_line.elaboration_cost_price + ) + self.assertAlmostEqual(self.sale_line.elaboration_margin, expected_margin) diff --git a/sale_elaboration_margin/views/sale_order_views.xml b/sale_elaboration_margin/views/sale_order_views.xml new file mode 100644 index 000000000..4ee100323 --- /dev/null +++ b/sale_elaboration_margin/views/sale_order_views.xml @@ -0,0 +1,29 @@ + + + + + sale.order + + + + + + + + + + + + +