Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
dd3c220
[ADD] sale_margin_delivered: New Module
chienandalu Jul 9, 2018
84ed49d
[IMP] sale_margin_delivered: Add new computed field for better contro…
sergio-teruel Nov 13, 2018
99d5930
[11.0][FIX] sale_margin_delivered: Set % delivered percent to 0.0 if …
sergio-teruel Jan 14, 2019
5ca1b9d
[11.0][FIX] sale_margin_delivered: Fix cost price unit from stock mov…
sergio-teruel Apr 15, 2019
6bc147b
[11.0][IMP] sale_margin_delivered: take an account returned moves
sergio-teruel Apr 16, 2019
45a65fd
[11.0][IMP] sale_margin_delivered: Compute avoid use product_uom_qty …
sergio-teruel Apr 17, 2019
cc4ed21
[IMP] stock_picking_comment_template: Change field label to fix travi…
sergio-teruel Dec 3, 2019
5b1d7a7
[IMP] sale_margin_delivered: black, isort
sergio-teruel Feb 24, 2020
ea95156
[MIG] sale_margin_delivered: Migration to v13.0
sergio-teruel Feb 24, 2020
fc7db8e
[FIX] sale_margin_delivered: Fix compute avco from stock valuation la…
sergio-teruel Sep 18, 2020
34534cd
[FIX] sale_margin_delivered: Fix cache miss error.
sergio-teruel Sep 22, 2020
cd47d38
[FIX] sale_margin_delivered: Fix division by zero if no price_reduce
sergio-teruel Sep 22, 2020
1137112
[FIX] sale_margin_delivered: Delivered values not zero when sale line…
carlosdauden Oct 8, 2020
62c7154
[FIX] sale_margin_delivered: Use Form in tests to avoid crash test du…
sergio-teruel Sep 6, 2021
8cc7cd6
[MIG] sale_margin_delivered: Migration to 15.0
CarlosRoca13 Nov 7, 2022
5dde111
[FIX] sale_margin_delivered: non storable
chienandalu Jan 3, 2022
5aeda53
[MIG] sale_margin_delivered: Migration to 16.0
pilarvargas-tecnativa Sep 12, 2023
7bd9143
[REF] split sale_margin_delivered into sale_margin_delivered and sale…
legalsylvain Sep 13, 2023
e26f4f7
[OU-ADD] sale_margin_delivered: Script to install sale_margin_deliver…
pilarvargas-tecnativa Sep 14, 2023
6f27dbb
Translated using Weblate (Spanish)
Ivorra78 Sep 27, 2023
70ccba7
[IMP] sale_margin_delivered: test performance improvement
josep-tecnativa Oct 20, 2023
fa6d5a8
Added translation using Weblate (Italian)
mymage Feb 1, 2024
32d1b83
Translated using Weblate (Italian)
mymage Feb 1, 2024
cbff335
[FIX] sale_margin_delivered: Fix calculation when more quantities are…
Shide May 31, 2024
9970837
Translated using Weblate (Italian)
mymage Jun 5, 2024
7a2c748
[FIX] sale_margin_delivered: Margin Delivered (%) help doesn't match …
Shide Jun 14, 2024
fe8825f
[REF] sale_margin_delivered: Preparate module to Dropshipping compati…
Shide Jun 18, 2024
451df4d
[FIX] sale_margin_delivered: Increase version due to multi commit on PR
Shide Jun 19, 2024
888d720
[FIX] sale_margin_delivered: Uses the right field to get price reduce
lmignon Jun 18, 2024
4dcfa65
[IMP] sale_margin_delivered: Improve UI
lmignon Jun 19, 2024
7efc740
[IMP] sale_margin_delivered: Store margin delivered percent as a frat…
lmignon Jun 19, 2024
50ed6ce
[FIX] sale_margin_analysis: Avoid ZeroDivisionError
lmignon Jun 20, 2024
c356d80
Translated using Weblate (Italian)
mymage Jun 24, 2024
03562e3
[IMP] sale_margin_delivered: pre-commit auto fixes
BhaveshHeliconia Feb 21, 2025
e6a2d95
[MIG] sale_margin_delivered: Migration to 17.0
BhaveshHeliconia Feb 21, 2025
38863c6
[REF] split sale_margin_delivered into sale_margin_delivered and sale…
legalsylvain Sep 13, 2023
d25c94f
[ADD] icon.png
OCA-git-bot Sep 15, 2023
4b4de93
Added translation using Weblate (Italian)
mymage Jan 22, 2024
dd1ded0
[IMP] sale_margin_delivered_security: combine with product_cost_security
yajo Mar 8, 2024
ce12410
Translated using Weblate (Italian)
mymage Apr 8, 2024
8bb8c8c
[FIX] sale_margin_delivered_security: Add security groups to right fi…
lmignon Jun 10, 2024
91d5810
Translated using Weblate (Italian)
mymage Jun 24, 2024
c975c6f
[IMP] sale_margin_delivered_security: pre-commit auto fixes
Nov 24, 2025
6f584c7
[MIG] sale_margin_delivered_security: Migration to 18.0
Nov 24, 2025
c2d6136
[UPD] Update sale_margin_delivered_security.pot
Nov 27, 2025
e36dd3f
[BOT] post-merge updates
OCA-git-bot Nov 27, 2025
ea3f259
[IMP] sale_margin_delivered_security: pre-commit auto fixes
rrebollo Feb 28, 2026
d595d08
[MIG] sale_margin_delivered_security: migration to 17.0 (backport fro…
rrebollo Feb 28, 2026
3b3eb87
[DON'T MERGE] test-requirements.txt
rrebollo Feb 28, 2026
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
Prev Previous commit
Next Next commit
[REF] sale_margin_delivered: Preparate module to Dropshipping compati…
…bility
  • Loading branch information
Shide authored and BhaveshHeliconia committed Dec 2, 2025
commit fe8825f322966d76fa07696fb49399ddb0989526
19 changes: 17 additions & 2 deletions sale_margin_delivered/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@ Sale Margin Delivered

Computes sale order lines margins for the delivered items.

This module takes in consideration Outgoing and Returns.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

This module has been developed to be able to show delivered margins on sale order lines.

If you need this module for those reasons, these might interest you too:

- sale_margin_delivered_dropshipping
- sale_report_delivered

Configuration
=============

Expand Down Expand Up @@ -111,10 +123,13 @@ promote its widespread use.
.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px
:target: https://github.com/sergio-teruel
:alt: sergio-teruel
.. |maintainer-Shide| image:: https://github.com/Shide.png?size=40px
:target: https://github.com/Shide
:alt: Shide

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|
|maintainer-sergio-teruel| |maintainer-Shide|

This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/16.0/sale_margin_delivered>`_ project on GitHub.

Expand Down
2 changes: 1 addition & 1 deletion sale_margin_delivered/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"data": ["views/sale_margin_delivered_view.xml"],
"installable": True,
"development_status": "Production/Stable",
"maintainers": ["sergio-teruel"],
"maintainers": ["sergio-teruel", "Shide"],
}
16 changes: 12 additions & 4 deletions sale_margin_delivered/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-14 12:15+0000\n"
"PO-Revision-Date: 2024-06-14 14:17+0200\n"
"POT-Creation-Date: 2024-06-19 07:32+0000\n"
"PO-Revision-Date: 2024-06-19 09:33+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
Expand All @@ -22,11 +22,19 @@ msgstr ""
msgid ""
"Average Unit Cost of delivered products.\n"
"\n"
"Formula: Value Delivered / Quantity Delivered"
"Formula: Value Delivered / Quantity Delivered\n"
"\n"
"When using the FIFO method, the value of this field may not match the actual cost of the product delivered.\n"
"There may also be differences with the costing of the Sales from Deliveries report, because when the sales order is created, it is not known exactly which units will actually be delivered to calculate their cost.\n"
"This is because when the sales order is created, it is not known which units will actually be delivered to calculate their actual cost. You do not have this information until you validate the corresponding delivery note."
msgstr ""
"Promedio del Coste Unitario de los productos entregados.\n"
"\n"
"Fórmula: Valor entregado / Cantidad Entregada"
"Fórmula: Valor entregado / Cantidad Entregada\n"
"\n"
"Cuando se usa el método FIFO el valor de este campo puede no coincidir con el coste real del producto entregado.\n"
"Puede haber también diferencias con el cálculo del coste del informe \"Ventas desde albaranes\".\n"
"El motivo es que al hacer el pedido de venta no se sabe todavía qué unidades serán las realmente entregadas para calcular su coste real. No se tendrá este dato hasta validar el albarán de entrega correspondiente."

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
Expand Down
8 changes: 7 additions & 1 deletion sale_margin_delivered/i18n/sale_margin_delivered.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-19 07:32+0000\n"
"PO-Revision-Date: 2024-06-19 07:32+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -18,7 +20,11 @@ msgstr ""
msgid ""
"Average Unit Cost of delivered products.\n"
"\n"
"Formula: Value Delivered / Quantity Delivered"
"Formula: Value Delivered / Quantity Delivered\n"
"\n"
"When using the FIFO method, the value of this field may not match the actual cost of the product delivered.\n"
"There may also be differences with the costing of the Sales from Deliveries report, because when the sales order is created, it is not known exactly which units will actually be delivered to calculate their cost.\n"
"This is because when the sales order is created, it is not known which units will actually be delivered to calculate their actual cost. You do not have this information until you validate the corresponding delivery note."
msgstr ""

#. module: sale_margin_delivered
Expand Down
47 changes: 32 additions & 15 deletions sale_margin_delivered/models/sale_margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,33 @@ class SaleOrderLine(models.Model):
compute="_compute_margin_delivered",
store=True,
help="Average Unit Cost of delivered products.\n\n"
"Formula: Value Delivered / Quantity Delivered",
"Formula: Value Delivered / Quantity Delivered\n\n"
"When using the FIFO method, the value of this field may not match the "
"actual cost of the product delivered.\n"
"There may also be differences with the costing of the Sales from "
"Deliveries report, because when the sales order is created, it is not known "
"exactly which units will actually be delivered to calculate their cost.\n"
"This is because when the sales order is created, it is not known which "
"units will actually be delivered to calculate their actual cost. You do not "
"have this information until you validate the corresponding delivery note.",
)

def _get_delivered_margin_valuation_layers(self):
"""Gets all Valuation Layers that should be considered for
Delivered Margin calculation."""
self.ensure_one()
valuation_layers = self.env["stock.valuation.layer"]
for move in self.move_ids.filtered(lambda m: m.state == "done"):
if move.picking_code == "outgoing":
# Outgoing moves have 1 valuation layer and are always negative
valuation_layers |= move.stock_valuation_layer_ids
elif move.picking_code == "incoming" and move.to_refund:
# Incoming moves have 2 valuation layers. Use positive one
valuation_layers |= move.stock_valuation_layer_ids.filtered(
lambda vl: vl.quantity > 0
)
return valuation_layers

@api.depends(
"margin",
"qty_delivered",
Expand All @@ -39,6 +63,10 @@ class SaleOrderLine(models.Model):
"move_ids.stock_valuation_layer_ids.quantity",
)
def _compute_margin_delivered(self):
"""Computes the Delivered Margin of the Lines.

It is calculated based on the Valuation Layers of each Line.
"""
digits = self.env["decimal.precision"].precision_get("Product Price")
self.margin_delivered = 0.0
self.margin_delivered_percent = 0.0
Expand All @@ -51,22 +79,11 @@ def _compute_margin_delivered(self):
line.price_subtotal - (price * line.qty_delivered)
)
line.purchase_price_delivery = price
continue
else:
moves = line.move_ids.filtered(
lambda x: (
x.state == "done"
and (
x.picking_code == "outgoing"
or (x.picking_code == "incoming" and x.to_refund)
)
)
)
# Qty and Value Delivered is negative when outgoing
value_delivered = sum(moves.mapped("stock_valuation_layer_ids.value"))
valuation_layers = line._get_delivered_margin_valuation_layers()
value_delivered = sum(valuation_layers.mapped("value"))
qty_delivered = (
sum(moves.mapped("stock_valuation_layer_ids.quantity"))
or -line.qty_delivered
sum(valuation_layers.mapped("quantity")) or -line.qty_delivered
)
# purchase_price_delivery always will be positive because division of same signs
line.purchase_price_delivery = tools.float_round(
Expand Down
6 changes: 6 additions & 0 deletions sale_margin_delivered/readme/CONTEXT.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module has been developed to be able to show delivered margins on sale order lines.

If you need this module for those reasons, these might interest you too:

- sale_margin_delivered_dropshipping
- sale_report_delivered
2 changes: 2 additions & 0 deletions sale_margin_delivered/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Computes sale order lines margins for the delivered items.

This module takes in consideration Outgoing and Returns.
54 changes: 34 additions & 20 deletions sale_margin_delivered/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -370,27 +371,38 @@ <h1 class="title">Sale Margin Delivered</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/sale_margin_delivered"><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-sale_margin_delivered"><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>Computes sale order lines margins for the delivered items.</p>
<p>This module takes in consideration Outgoing and Returns.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
<li><a class="reference internal" href="#use-cases-context" id="toc-entry-1">Use Cases / Context</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-3">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="use-cases-context">
<h1><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h1>
<p>This module has been developed to be able to show delivered margins on sale order lines.</p>
<p>If you need this module for those reasons, these might interest you too:</p>
<ul class="simple">
<li>sale_margin_delivered_dropshipping</li>
<li>sale_report_delivered</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>To grant Sales Margin view privileges to a user, go to <em>Settings &gt; Users &amp;
Companies &gt; Users</em>, select the user and set <em>Show Sale Margin</em> on.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<ol class="arabic simple">
<li>Go to <em>Sales &gt; Orders &gt; Quotations</em>.</li>
<li>Create a new <em>Sales Order</em> and add a line with an stockable product. Set a
Expand All @@ -409,23 +421,23 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
order line.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<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:%20sale_margin_delivered%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-4">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Sergio Teruel</li>
Expand All @@ -439,14 +451,16 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<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" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a></p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/Shide"><img alt="Shide" src="https://github.com/Shide.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/margin-analysis/tree/16.0/sale_margin_delivered">OCA/margin-analysis</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
Loading