diff --git a/product_margin_report_landed_costs/README.rst b/product_margin_report_landed_costs/README.rst new file mode 100644 index 00000000..daa0530f --- /dev/null +++ b/product_margin_report_landed_costs/README.rst @@ -0,0 +1,94 @@ +================================== +Product margin report landed costs +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5b02242f5dbe90213a92d0d2632daa7f4c6b7553a8057302a5ab4f1f79657f90 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmargin--analysis-lightgray.png?logo=github + :target: https://github.com/OCA/margin-analysis/tree/17.0/product_margin_report_landed_costs + :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-17-0/margin-analysis-17-0-product_margin_report_landed_costs + :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=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to add landed costs associated with the product +to the Product Margins report. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Product margin - Landed cost +---------------------------- + +1. Go to Invoicing > Reporting > Product Margins +2. Select the filters and click the Open Margins button. +3. Select an item from the list and you'll see the new Landed Costs + section. + +|LANDED_COSTS| + +.. |LANDED_COSTS| image:: https://raw.githubusercontent.com/OCA/margin-analysis/17.0/product_margin_report_landed_costs/static/img/readme/LANDED_COSTS.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 +------- + +* Binhex + +Contributors +------------ + +- [Binhex] (https://www.binhex.cloud): + + - Edilio Escalona Almira e.escalona@binhex.cloud + +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/product_margin_report_landed_costs/__init__.py b/product_margin_report_landed_costs/__init__.py new file mode 100644 index 00000000..0077c886 --- /dev/null +++ b/product_margin_report_landed_costs/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 Binhex +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/product_margin_report_landed_costs/__manifest__.py b/product_margin_report_landed_costs/__manifest__.py new file mode 100644 index 00000000..42a89723 --- /dev/null +++ b/product_margin_report_landed_costs/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 Binhex +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Product margin report landed costs", + "summary": """Add the landed costs associated with the product + to the Product Margins report.""", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "Binhex,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/margin-analysis", + "depends": [ + "stock_landed_costs", + "product_margin", + ], + "data": ["views/product_product_views.xml"], +} diff --git a/product_margin_report_landed_costs/i18n/es.po b/product_margin_report_landed_costs/i18n/es.po new file mode 100644 index 00000000..d8c0ecfb --- /dev/null +++ b/product_margin_report_landed_costs/i18n/es.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_margin_report_landed_costs +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-08-05 15:23+0000\n" +"PO-Revision-Date: 2025-08-05 15:23+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_margin_report_landed_costs +#: model:ir.model.fields,help:product_margin_report_landed_costs.field_product_product__purchase_avg_price +msgid "" +"(Total cost (Purchase) + Accumulated landed costs) / # Invoiced in Purchase" +msgstr "(Coste total (Compra) + Gastos de envio acumulados) / # Facturado en compra" + +#. module: product_margin_report_landed_costs +#: model:ir.model.fields,field_description:product_margin_report_landed_costs.field_product_product__accumulated_landed_costs +msgid "Accumulated Landed Costs" +msgstr "Gastos de envio acumulados" + +#. module: product_margin_report_landed_costs +#: model:ir.model.fields,field_description:product_margin_report_landed_costs.field_product_product__purchase_avg_price +msgid "Avg. Purchase Unit Price" +msgstr "Precio unitario medio de compra" + +#. module: product_margin_report_landed_costs +#: model_terms:ir.ui.view,arch_db:product_margin_report_landed_costs.product_margin_view_form +msgid "Landed Costs" +msgstr "Gastos de envio" + +#. module: product_margin_report_landed_costs +#: model:ir.model,name:product_margin_report_landed_costs.model_product_product +msgid "Product Variant" +msgstr "Variante de producto" + +#. module: product_margin_report_landed_costs +#: model:ir.model.fields,help:product_margin_report_landed_costs.field_product_product__accumulated_landed_costs +msgid "" +"Summation of all landed costs associated with the product in the filtered " +"period." +msgstr "" +"Sumatoria de los costos de destino asociados al producto en el período filtrado." + +#. module: product_margin_report_landed_costs +#: model:ir.model.fields,field_description:product_margin_report_landed_costs.field_product_product__total_margin +msgid "Total Margin" +msgstr "Margen total" + +#. module: product_margin_report_landed_costs +#: model:ir.model.fields,help:product_margin_report_landed_costs.field_product_product__total_margin +msgid "Turnover - (# Invoiced in Sale * Avg. Unit Price (Purchases))" +msgstr "Volumen de negocio - (# Facturado en venta * Precio unitario medio (Compras)" diff --git a/product_margin_report_landed_costs/models/__init__.py b/product_margin_report_landed_costs/models/__init__.py new file mode 100644 index 00000000..57112ab7 --- /dev/null +++ b/product_margin_report_landed_costs/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2025 Binhex +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from . import product_product diff --git a/product_margin_report_landed_costs/models/product_product.py b/product_margin_report_landed_costs/models/product_product.py new file mode 100644 index 00000000..a435e66f --- /dev/null +++ b/product_margin_report_landed_costs/models/product_product.py @@ -0,0 +1,60 @@ +# Copyright 2025 Binhex +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + accumulated_landed_costs = fields.Float( + compute="_compute_product_margin_fields_values", + help="Summation of all landed costs associated" + " with the product in the filtered period.", + ) + + purchase_avg_price = fields.Float( + help="(Total cost (Purchase) + " + "Accumulated landed costs) / # Invoiced in Purchase", + ) + + total_margin = fields.Float( + help="Turnover - (# Invoiced in Sale * Avg. Unit Price (Purchases))", + ) + + def _compute_product_margin_fields_values(self): + res = super()._compute_product_margin_fields_values() + StockValuationAdjustmentLines = self.env["stock.valuation.adjustment.lines"] + for product in self: + product_values = res[product.id] + adjustment_lines = StockValuationAdjustmentLines._read_group( + domain=[ + ("product_id", "=", product.id), + ("cost_id.date", ">=", product_values["date_from"]), + ("cost_id.date", "<=", product_values["date_to"]), + ], + groupby=["product_id"], + aggregates=["additional_landed_cost:sum"], + ) + accumulated_landed_cost = 0 + if adjustment_lines: + accumulated_landed_cost = ( + adjustment_lines[0][1] + if adjustment_lines and adjustment_lines[0][0] == product + else 0 + ) + + product_values["accumulated_landed_costs"] = accumulated_landed_cost + product_values["purchase_avg_price"] = ( + (product_values["total_cost"] + accumulated_landed_cost) + / product_values["purchase_num_invoiced"] + if product_values["purchase_num_invoiced"] > 0 + else 0 + ) + product_values["total_margin"] = product_values["turnover"] - ( + product_values["sale_num_invoiced"] + * product_values["purchase_avg_price"] + ) + + product.update(res[product.id]) + return res diff --git a/product_margin_report_landed_costs/pyproject.toml b/product_margin_report_landed_costs/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/product_margin_report_landed_costs/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_margin_report_landed_costs/readme/CONTRIBUTORS.md b/product_margin_report_landed_costs/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..ab4e0fb4 --- /dev/null +++ b/product_margin_report_landed_costs/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Binhex] (https://www.binhex.cloud): + - Edilio Escalona Almira diff --git a/product_margin_report_landed_costs/readme/DESCRIPTION.md b/product_margin_report_landed_costs/readme/DESCRIPTION.md new file mode 100644 index 00000000..8410e362 --- /dev/null +++ b/product_margin_report_landed_costs/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows you to add landed costs associated with the product to the Product Margins report. diff --git a/product_margin_report_landed_costs/readme/USAGE.md b/product_margin_report_landed_costs/readme/USAGE.md new file mode 100644 index 00000000..4d777c4b --- /dev/null +++ b/product_margin_report_landed_costs/readme/USAGE.md @@ -0,0 +1,8 @@ +Product margin - Landed cost +------------------------ + +1. Go to Invoicing > Reporting > Product Margins +2. Select the filters and click the Open Margins button. +3. Select an item from the list and you'll see the new Landed Costs section. + + ![LANDED_COSTS](../static/img/readme/LANDED_COSTS.png) diff --git a/product_margin_report_landed_costs/static/description/index.html b/product_margin_report_landed_costs/static/description/index.html new file mode 100644 index 00000000..a7754a23 --- /dev/null +++ b/product_margin_report_landed_costs/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +Product margin report landed costs + + + +
+

Product margin report landed costs

+ + +

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

+

This module allows you to add landed costs associated with the product +to the Product Margins report.

+

Table of contents

+ +
+

Usage

+
+

Product margin - Landed cost

+
    +
  1. Go to Invoicing > Reporting > Product Margins
  2. +
  3. Select the filters and click the Open Margins button.
  4. +
  5. Select an item from the list and you’ll see the new Landed Costs +section.
  6. +
+

LANDED_COSTS

+
+
+
+

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

+
    +
  • Binhex
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/product_margin_report_landed_costs/static/img/readme/LANDED_COSTS.png b/product_margin_report_landed_costs/static/img/readme/LANDED_COSTS.png new file mode 100644 index 00000000..e871b84e Binary files /dev/null and b/product_margin_report_landed_costs/static/img/readme/LANDED_COSTS.png differ diff --git a/product_margin_report_landed_costs/tests/__init__.py b/product_margin_report_landed_costs/tests/__init__.py new file mode 100644 index 00000000..efc5810e --- /dev/null +++ b/product_margin_report_landed_costs/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 Binhex +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_product_margin_report_landed_costs diff --git a/product_margin_report_landed_costs/tests/test_product_margin_report_landed_costs.py b/product_margin_report_landed_costs/tests/test_product_margin_report_landed_costs.py new file mode 100644 index 00000000..0d8a25fb --- /dev/null +++ b/product_margin_report_landed_costs/tests/test_product_margin_report_landed_costs.py @@ -0,0 +1,72 @@ +# Copyright 2025 Binhex +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from unittest.mock import patch + +from odoo.addons.base.tests.common import BaseCommon +from odoo.addons.product_margin.models.product_product import ProductProduct + + +class TestProductMarginAccumulatedLandedCost(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.category_avg = cls.env["product.category"].create( + { + "name": "Cat Test", + "property_cost_method": "average", + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Produtc Test", + "detailed_type": "product", + "categ_id": cls.category_avg.id, + "company_id": cls.env.company.id, + } + ) + + def test_compute_product_margin_fields_values(self): + product = self.product + super_result = { + product.id: { + "sale_num_invoiced": 10.0, + "purchase_num_invoiced": 5.0, + "total_cost": 50.0, + "turnover": 200.0, + "date_from": "2022-01-01", + "date_to": "2022-12-31", + } + } + fake_accumulated_cost = 100.0 + StockValuationAdjustmentLines = self.env["stock.valuation.adjustment.lines"] + with patch.object( + ProductProduct, + "_compute_product_margin_fields_values", + return_value=super_result, + ): + with patch.object( + type(StockValuationAdjustmentLines), + "_read_group", + return_value=[(product, fake_accumulated_cost)], + ): + result = product._compute_product_margin_fields_values() + self.assertEqual( + result[product.id]["accumulated_landed_costs"], + fake_accumulated_cost, + ) + expected_avg_price = ( + super_result[product.id]["total_cost"] + fake_accumulated_cost + ) / super_result[product.id]["purchase_num_invoiced"] + + expected_margin = super_result[product.id]["turnover"] - ( + super_result[product.id]["sale_num_invoiced"] * expected_avg_price + ) + self.assertEqual( + result[product.id]["purchase_avg_price"], + expected_avg_price, + ) + self.assertEqual( + result[product.id]["total_margin"], + expected_margin, + ) diff --git a/product_margin_report_landed_costs/views/product_product_views.xml b/product_margin_report_landed_costs/views/product_product_views.xml new file mode 100644 index 00000000..fc62afa7 --- /dev/null +++ b/product_margin_report_landed_costs/views/product_product_views.xml @@ -0,0 +1,16 @@ + + + + + product.margin.form.inherit.product_margin_report_sale_margin + + product.product + + + + + + + + +