Skip to content

Commit fd3dd39

Browse files
committed
[ADD] product_margin_report_landed_costs: Add the landed costs associated with the product to the Product Margins report.
1 parent 74ef322 commit fd3dd39

16 files changed

Lines changed: 760 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
==================================
2+
Product margin report landed costs
3+
==================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:5b02242f5dbe90213a92d0d2632daa7f4c6b7553a8057302a5ab4f1f79657f90
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github
20+
:target: https://github.com/OCA/margin-analysis/tree/17.0/product_margin_report_landed_costs
21+
:alt: OCA/margin-analysis
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/margin-analysis-17-0/margin-analysis-17-0-product_margin_report_landed_costs
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/margin-analysis&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows you to add landed costs associated with the product
32+
to the Product Margins report.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Usage
40+
=====
41+
42+
43+
44+
Bug Tracker
45+
===========
46+
47+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/margin-analysis/issues>`_.
48+
In case of trouble, please check there if your issue has already been reported.
49+
If you spotted it first, help us to smash it by providing a detailed and welcomed
50+
`feedback <https://github.com/OCA/margin-analysis/issues/new?body=module:%20product_margin_report_landed_costs%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
52+
Do not contact contributors directly about support or help with technical issues.
53+
54+
Credits
55+
=======
56+
57+
Authors
58+
-------
59+
60+
* Binhex
61+
62+
Contributors
63+
------------
64+
65+
- [Binhex Cloud] (https://www.binhex.cloud):
66+
67+
- Edilio Escalona Almira e.escalona@binhex.cloud
68+
69+
Maintainers
70+
-----------
71+
72+
This module is maintained by the OCA.
73+
74+
.. image:: https://odoo-community.org/logo.png
75+
:alt: Odoo Community Association
76+
:target: https://odoo-community.org
77+
78+
OCA, or the Odoo Community Association, is a nonprofit organization whose
79+
mission is to support the collaborative development of Odoo features and
80+
promote its widespread use.
81+
82+
This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/17.0/product_margin_report_landed_costs>`_ project on GitHub.
83+
84+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2025 Binhex <https://www.binhex.cloud>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from . import models
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Binhex <https://www.binhex.cloud>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Product margin report landed costs",
6+
"summary": """Add the landed costs associated with the product
7+
to the Product Margins report.""",
8+
"version": "17.0.1.0.0",
9+
"license": "AGPL-3",
10+
"author": "Binhex,Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/margin-analysis",
12+
"depends": [
13+
"stock_landed_costs",
14+
"product_margin",
15+
],
16+
"data": ["views/product_product_views.xml"],
17+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * product_margin_report_landed_costs
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2025-08-05 15:23+0000\n"
10+
"PO-Revision-Date: 2025-08-05 15:23+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: product_margin_report_landed_costs
19+
#: model:ir.model.fields,help:product_margin_report_landed_costs.field_product_product__purchase_avg_price
20+
msgid ""
21+
"(Total cost (Purchase) + Accumulated landed costs) / # Invoiced in Purchase"
22+
msgstr "(Coste total (Compra) + Gastos de envio acumulados) / # Facturado en compra"
23+
24+
#. module: product_margin_report_landed_costs
25+
#: model:ir.model.fields,field_description:product_margin_report_landed_costs.field_product_product__accumulated_landed_costs
26+
msgid "Accumulated Landed Costs"
27+
msgstr "Gastos de envio acumulados"
28+
29+
#. module: product_margin_report_landed_costs
30+
#: model:ir.model.fields,field_description:product_margin_report_landed_costs.field_product_product__purchase_avg_price
31+
msgid "Avg. Purchase Unit Price"
32+
msgstr "Precio unitario medio de compra"
33+
34+
#. module: product_margin_report_landed_costs
35+
#: model_terms:ir.ui.view,arch_db:product_margin_report_landed_costs.product_margin_view_form
36+
msgid "Landed Costs"
37+
msgstr "Gastos de envio"
38+
39+
#. module: product_margin_report_landed_costs
40+
#: model:ir.model,name:product_margin_report_landed_costs.model_product_product
41+
msgid "Product Variant"
42+
msgstr "Variante de producto"
43+
44+
#. module: product_margin_report_landed_costs
45+
#: model:ir.model.fields,help:product_margin_report_landed_costs.field_product_product__accumulated_landed_costs
46+
msgid ""
47+
"Summation of all landed costs associated with the product in the filtered "
48+
"period."
49+
msgstr ""
50+
"Sumatoria de los costos de destino asociados al producto en el período filtrado."
51+
52+
#. module: product_margin_report_landed_costs
53+
#: model:ir.model.fields,field_description:product_margin_report_landed_costs.field_product_product__total_margin
54+
msgid "Total Margin"
55+
msgstr "Margen total"
56+
57+
#. module: product_margin_report_landed_costs
58+
#: model:ir.model.fields,help:product_margin_report_landed_costs.field_product_product__total_margin
59+
msgid "Turnover - (# Invoiced in Sale * Avg. Unit Price (Purchases))"
60+
msgstr "Volumen de negocio - (# Facturado en venta * Precio unitario medio (Compras)"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2025 Binhex <https://www.binhex.cloud>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
5+
from . import product_product
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2025 Binhex <https://www.binhex.cloud>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ProductProduct(models.Model):
8+
_inherit = "product.product"
9+
10+
accumulated_landed_costs = fields.Float(
11+
compute="_compute_product_margin_fields_values",
12+
help="Summation of all landed costs associated"
13+
" with the product in the filtered period.",
14+
)
15+
16+
purchase_avg_price = fields.Float(
17+
help="(Total cost (Purchase) + "
18+
"Accumulated landed costs) / # Invoiced in Purchase",
19+
)
20+
21+
total_margin = fields.Float(
22+
help="Turnover - (# Invoiced in Sale * Avg. Unit Price (Purchases))",
23+
)
24+
25+
def _compute_product_margin_fields_values(self):
26+
res = super()._compute_product_margin_fields_values()
27+
StockValuationAdjustmentLines = self.env["stock.valuation.adjustment.lines"]
28+
for product in self:
29+
product_values = res[product.id]
30+
adjusment_lines = StockValuationAdjustmentLines._read_group(
31+
domain=[
32+
("product_id", "=", product.id),
33+
("cost_id.date", ">=", product_values["date_from"]),
34+
("cost_id.date", "<=", product_values["date_to"]),
35+
],
36+
groupby=["product_id"],
37+
aggregates=["additional_landed_cost:sum"],
38+
)
39+
accumulated_landed_cost = 0
40+
if adjusment_lines:
41+
accumulated_landed_cost = (
42+
adjusment_lines[0][1]
43+
if adjusment_lines and adjusment_lines[0][0] == product
44+
else 0
45+
)
46+
47+
product_values["accumulated_landed_costs"] = accumulated_landed_cost
48+
product_values["purchase_avg_price"] = (
49+
(product_values["total_cost"] + accumulated_landed_cost)
50+
/ product_values["purchase_num_invoiced"]
51+
if product_values["purchase_num_invoiced"] > 0
52+
else 0
53+
)
54+
product_values["total_margin"] = product_values["turnover"] - (
55+
product_values["sale_num_invoiced"]
56+
* product_values["purchase_avg_price"]
57+
)
58+
59+
product.update(res[product.id])
60+
return res
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Binhex Cloud] (https://www.binhex.cloud):
2+
- Edilio Escalona Almira <e.escalona@binhex.cloud>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module allows you to add landed costs associated with the product to the Product Margins report.

product_margin_report_landed_costs/readme/USAGE.md

Whitespace-only changes.

0 commit comments

Comments
 (0)