Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions product_standard_margin/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==============================
Product Margin and Margin Rate
==============================
Expand All @@ -13,7 +17,7 @@ Product Margin and Margin Rate
.. |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
.. |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
Expand Down Expand Up @@ -57,8 +61,10 @@ have added a dependency on sale module.
Known issues / Roadmap
======================

* This module will not work properly if used in a multicompany context with product
prices depending on the company.
This module will not work properly if used in a multicompany context with "global" products
that are not related to any company.
This is due to current odoo limitation that compute field with a sudo user, and due to the field `standard_price`
that is weirdly company dependent, unlike the selling price.

Bug Tracker
===========
Expand Down
2 changes: 1 addition & 1 deletion product_standard_margin/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Product Margin and Margin Rate",
"version": "16.0.1.0.3",
"version": "16.0.2.0.0",
"author": "Camptocamp,GRAP,Odoo Community Association (OCA)",
"category": "Product",
"depends": ["account"],
Expand Down
30 changes: 30 additions & 0 deletions product_standard_margin/migrations/16.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)


def migrate(cr, version):
if not version:
return

env = api.Environment(cr, SUPERUSER_ID, {})

for company in env["res.company"].with_context(active_test=False).search([]):
products = (
env["product.product"]
.with_company(company)
.search(
[
("company_id", "=", company.id),
("standard_markup_rate", "=", 999.0),
("standard_price", "!=", 0.0),
]
)
)
_logger.info(
f"Company {company.name}:"
f" Trying to recomputing margin fields for {len(products)} products ..."
)
products._compute_margin()
13 changes: 6 additions & 7 deletions product_standard_margin/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,24 @@ class ProductProduct(models.Model):
)
def _compute_margin(self):
for product in self:
standard_price = product.with_company(product.company_id).standard_price
product.list_price_vat_excl = product.taxes_id.compute_all(
product.lst_price, product=product
)["total_excluded"]
product.standard_margin = (
product.list_price_vat_excl - product.standard_price
)
product.standard_margin = product.list_price_vat_excl - standard_price
if product.list_price_vat_excl == 0:
product.standard_margin_rate = 999.0
else:
product.standard_margin_rate = (
(product.list_price_vat_excl - product.standard_price)
(product.list_price_vat_excl - standard_price)
/ product.list_price_vat_excl
* 100
)
if product.standard_price == 0:
if standard_price == 0:
product.standard_markup_rate = 999.0
else:
product.standard_markup_rate = (
(product.list_price_vat_excl - product.standard_price)
/ product.standard_price
(product.list_price_vat_excl - standard_price)
/ standard_price
* 100
)
13 changes: 6 additions & 7 deletions product_standard_margin/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ def _compute_margin(self):
# because otherwise, the recomputation is not done correctly
# when the product datas are changed from the template view
for template in self:
standard_price = template.with_company(template.company_id).standard_price
template.list_price_vat_excl = template.taxes_id.compute_all(
template.list_price, product=template
)["total_excluded"]
template.standard_margin = (
template.list_price_vat_excl - template.standard_price
)
template.standard_margin = template.list_price_vat_excl - standard_price
if template.list_price_vat_excl == 0:
template.standard_margin_rate = 999.0
else:
template.standard_margin_rate = (
(template.list_price_vat_excl - template.standard_price)
(template.list_price_vat_excl - standard_price)
/ template.list_price_vat_excl
* 100
)
if template.standard_price == 0:
if standard_price == 0:
template.standard_markup_rate = 999.0
else:
template.standard_markup_rate = (
(template.list_price_vat_excl - template.standard_price)
/ template.standard_price
(template.list_price_vat_excl - standard_price)
/ standard_price
* 100
)
6 changes: 4 additions & 2 deletions product_standard_margin/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
* This module will not work properly if used in a multicompany context with product
prices depending on the company.
This module will not work properly if used in a multicompany context with "global" products
that are not related to any company.
This is due to current odoo limitation that compute field with a sudo user, and due to the field `standard_price`
that is weirdly company dependent, unlike the selling price.
34 changes: 20 additions & 14 deletions product_standard_margin/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Product Margin and Margin Rate</title>
<title>README.rst</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,16 +360,21 @@
</style>
</head>
<body>
<div class="document" id="product-margin-and-margin-rate">
<h1 class="title">Product Margin and Margin Rate</h1>
<div class="document">


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="product-margin-and-margin-rate">
<h1>Product Margin and Margin Rate</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fabfa924e777dbded2cd92955a1fa804c4ad0f5afa6157ea2f3a7facde8c37e4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/margin-analysis/tree/16.0/product_standard_margin"><img alt="OCA/margin-analysis" src="https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/margin-analysis-16-0/margin-analysis-16-0-product_standard_margin"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/margin-analysis&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/margin-analysis/tree/16.0/product_standard_margin"><img alt="OCA/margin-analysis" src="https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/margin-analysis-16-0/margin-analysis-16-0-product_standard_margin"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/margin-analysis&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Add 2 fields on the product form that compute the standard (or theorical)
margin and markup based on the current values of sale and standard price
present in the product form. We take care of taxe included or excluded.</p>
Expand Down Expand Up @@ -402,31 +407,31 @@ <h1 class="title">Product Margin and Margin Rate</h1>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>This module will not work properly if used in a multicompany context with product
prices depending on the company.</li>
</ul>
<h2><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h2>
<p>This module will not work properly if used in a multicompany context with “global” products
that are not related to any company.
This is due to current odoo limitation that compute field with a sudo user, and due to the field <cite>standard_price</cite>
that is weirdly company dependent, unlike the selling price.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/margin-analysis/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/margin-analysis/issues/new?body=module:%20product_standard_margin%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
<ul class="simple">
<li>Camptocamp</li>
<li>GRAP</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
<ul class="simple">
<li>Alexandre Fayolle &lt;<a class="reference external" href="mailto:alexandre.fayolle&#64;camptocamp.com">alexandre.fayolle&#64;camptocamp.com</a>&gt;</li>
<li>Yannick Vaucher &lt;<a class="reference external" href="mailto:yannick.vaucher&#64;camptocamp.com">yannick.vaucher&#64;camptocamp.com</a>&gt;</li>
Expand All @@ -436,7 +441,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -451,5 +456,6 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
</div>
</div>
</div>
</div>
</body>
</html>
Loading