Skip to content

Commit 64a5592

Browse files
committed
[ADD] product_margin_report_sale_margin: Add new fields for sales margin in the Product Margins report
[IMP] product_margin_report_sale_margin: Add tests
1 parent 74ef322 commit 64a5592

16 files changed

Lines changed: 740 additions & 0 deletions

File tree

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
==========================
2+
Product report sale margin
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_sale_margin
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_sale_margin
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 adds 2 new fields for calculating the Sales margin.
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Usage
39+
=====
40+
41+
Sales margin fields
42+
-------------------
43+
44+
1. Go to *Invoicing* > *Reporting* -> Product Margins
45+
46+
2. Select the values you want to filter by.
47+
48+
3. Click on the *Open margins* button.
49+
50+
4. When the new view is displayed, the two new fields are visible;
51+
similarly, if you select an element, they will be visible in the form
52+
view.
53+
54+
|FIELDS_VIEW_TREE|
55+
56+
|FIELDS_VIEW_FORM|
57+
58+
Field calculations
59+
------------------
60+
61+
- Sales margin = Turnover - (# Invoiced in Sale \* Avg. Unit Price
62+
[Purchases])
63+
- Sales margin rate = (Sales margin - \* 100) / Turnover
64+
65+
.. |FIELDS_VIEW_TREE| image:: https://raw.githubusercontent.com/OCA/margin-analysis/17.0/product_margin_report_sale_margin/static/img/readme/FIELDS_VIEW_TREE.png
66+
.. |FIELDS_VIEW_FORM| image:: https://raw.githubusercontent.com/OCA/margin-analysis/17.0/product_margin_report_sale_margin/static/img/readme/FIELDS_VIEW_FORM.png
67+
68+
Bug Tracker
69+
===========
70+
71+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/margin-analysis/issues>`_.
72+
In case of trouble, please check there if your issue has already been reported.
73+
If you spotted it first, help us to smash it by providing a detailed and welcomed
74+
`feedback <https://github.com/OCA/margin-analysis/issues/new?body=module:%20product_margin_report_sale_margin%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
75+
76+
Do not contact contributors directly about support or help with technical issues.
77+
78+
Credits
79+
=======
80+
81+
Authors
82+
-------
83+
84+
* Binhex
85+
86+
Contributors
87+
------------
88+
89+
- [Binhex Cloud] (https://www.binhex.cloud):
90+
91+
- Edilio Escalona Almira e.escalona@binhex.cloud
92+
93+
Maintainers
94+
-----------
95+
96+
This module is maintained by the OCA.
97+
98+
.. image:: https://odoo-community.org/logo.png
99+
:alt: Odoo Community Association
100+
:target: https://odoo-community.org
101+
102+
OCA, or the Odoo Community Association, is a nonprofit organization whose
103+
mission is to support the collaborative development of Odoo features and
104+
promote its widespread use.
105+
106+
This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/17.0/product_margin_report_sale_margin>`_ project on GitHub.
107+
108+
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 report sale margin",
6+
"summary": """Add new fields for sales margin in the Product Margins report.""",
7+
"version": "17.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Binhex,Odoo Community Association (OCA)",
10+
"website": "https://github.com/OCA/margin-analysis",
11+
"depends": [
12+
"product_margin",
13+
],
14+
"data": ["views/product_product_views.xml"],
15+
}
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
sales_margin = fields.Float(compute="_compute_product_margin_fields_values")
11+
sales_margin_rate = fields.Float(compute="_compute_product_margin_fields_values")
12+
13+
def _compute_product_margin_fields_values(self):
14+
res = super()._compute_product_margin_fields_values()
15+
for product in self:
16+
product_values = res[product.id]
17+
product_values["sales_margin"] = product_values["turnover"] - (
18+
product_values["sale_num_invoiced"]
19+
* product_values["purchase_avg_price"]
20+
)
21+
product_values["sales_margin_rate"] = (
22+
product_values["sales_margin"] * 100
23+
) / (product_values["turnover"] or 1)
24+
product.update(res[product.id])
25+
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 adds 2 new fields for calculating the Sales margin.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Sales margin fields
2+
------------------
3+
4+
1. Go to *Invoicing* > *Reporting* -> Product Margins
5+
2. Select the values you want to filter by.
6+
3. Click on the *Open margins* button.
7+
4. When the new view is displayed, the two new fields are visible; similarly,
8+
if you select an element, they will be visible in the form view.
9+
10+
![FIELDS_VIEW_TREE](../static/img/readme/FIELDS_VIEW_TREE.png)
11+
12+
![FIELDS_VIEW_FORM](../static/img/readme/FIELDS_VIEW_FORM.png)
13+
14+
15+
Field calculations
16+
------------------
17+
* Sales margin = Turnover - (# Invoiced in Sale * Avg. Unit Price [Purchases])
18+
* Sales margin rate = (Sales margin - * 100) / Turnover
19+

0 commit comments

Comments
 (0)