From 6ed45cf2f8c106aac2f4a8d62d1273ebb8dbb694 Mon Sep 17 00:00:00 2001 From: Edilio Escalona Almira Date: Thu, 11 Sep 2025 14:13:21 -0500 Subject: [PATCH] [ADD] product_margin_report_landed_costs: Add the landed costs associated with the product to the Product Margins report. --- product_margin_report_landed_costs/README.rst | 94 ++++ .../__init__.py | 4 + .../__manifest__.py | 17 + product_margin_report_landed_costs/i18n/es.po | 60 +++ .../models/__init__.py | 5 + .../models/product_product.py | 60 +++ .../pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 2 + .../readme/DESCRIPTION.md | 1 + .../readme/USAGE.md | 8 + .../static/description/index.html | 444 ++++++++++++++++++ .../static/img/readme/LANDED_COSTS.png | Bin 0 -> 4263 bytes .../tests/__init__.py | 4 + ...test_product_margin_report_landed_costs.py | 72 +++ .../views/product_product_views.xml | 16 + 15 files changed, 790 insertions(+) create mode 100644 product_margin_report_landed_costs/README.rst create mode 100644 product_margin_report_landed_costs/__init__.py create mode 100644 product_margin_report_landed_costs/__manifest__.py create mode 100644 product_margin_report_landed_costs/i18n/es.po create mode 100644 product_margin_report_landed_costs/models/__init__.py create mode 100644 product_margin_report_landed_costs/models/product_product.py create mode 100644 product_margin_report_landed_costs/pyproject.toml create mode 100644 product_margin_report_landed_costs/readme/CONTRIBUTORS.md create mode 100644 product_margin_report_landed_costs/readme/DESCRIPTION.md create mode 100644 product_margin_report_landed_costs/readme/USAGE.md create mode 100644 product_margin_report_landed_costs/static/description/index.html create mode 100644 product_margin_report_landed_costs/static/img/readme/LANDED_COSTS.png create mode 100644 product_margin_report_landed_costs/tests/__init__.py create mode 100644 product_margin_report_landed_costs/tests/test_product_margin_report_landed_costs.py create mode 100644 product_margin_report_landed_costs/views/product_product_views.xml diff --git a/product_margin_report_landed_costs/README.rst b/product_margin_report_landed_costs/README.rst new file mode 100644 index 000000000..daa0530fe --- /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 000000000..0077c8866 --- /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 000000000..42a897232 --- /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 000000000..d8c0ecfbd --- /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 000000000..57112ab7f --- /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 000000000..a435e66fb --- /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 000000000..4231d0ccc --- /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 000000000..ab4e0fb41 --- /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 000000000..8410e3629 --- /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 000000000..4d777c4b9 --- /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 000000000..a7754a232 --- /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 0000000000000000000000000000000000000000..e871b84e797ba548b2549f0b8c4dde4f13f34b9d GIT binary patch literal 4263 zcmcgwS5y7);;&-KAd&m&daQs?_p-op859v)|X_cuR%k3my(2pghoqK)tH3j2IzVY zy+wXKmc^8ll915*XsIfh2HEW`Uzsqva#7$e&Ir{LZdIJyFFoXAR`}cRQBIS4Bn$g4 ztTY9=XHce6f|+#6n4Z$rl``x5XY&LKcu?{PL>o#ZfBg>g!A!bjjc2BlY!$8t_qhbb zhPUMF`C@{5z1|UH=mGAVbQ4Ufs&dcqfDAY*Ott($JP_cXgw;^BcKkmf0e}2Bo#q~U z=r(#jZErm z|I=qLbKk~Z>a-a!$}BLqmbpC~utht@zV`J(9GGQkSF@dADA5&O&cL;kGh8D+f4;!n zwztmdQ+=?Rn>43$8zVWg3^B%8d-Z+d2c{bm{;;|br$YKeQkv70bEgCFYZH+gl*SxL zYrBBgFT@c6i-yzf5j-P#9C7xR>OGJ{#t_dk`*pZiMSH*C3H8Sjcmih6WL=T6=IPYj z+`XKN#S}j;l%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*nKV%PPqQG+uREb^fs0yP5>aC=kwH~AN7EcZFy&?R-o`rG~C zJyE0h^j3@wOH{%Q+H5R5IW3jw(6=4@b6)t`WtuQ)iGCtG*A?gp-+#6G{7-ptMMg1y WZ$s8@Q0KY +# 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 000000000..0d8a25fb6 --- /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 000000000..fc62afa77 --- /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 + + + + + + + + +