Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
[MIG] sale_margin_sync: Migration to 14.0
  • Loading branch information
rafamarpe authored and BhaveshHeliconia committed Dec 15, 2025
commit bbac7e4eec7c35ea854f2d9843ee6f4d8d1912a8
10 changes: 5 additions & 5 deletions sale_margin_sync/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Sale margin sync
: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/13.0/sale_margin_sync
:target: https://github.com/OCA/margin-analysis/tree/14.0/sale_margin_sync
: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-13-0/margin-analysis-13-0-sale_margin_sync
:target: https://translation.odoo-community.org/projects/margin-analysis-14-0/margin-analysis-14-0-sale_margin_sync
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/132/13.0
:target: https://runbot.odoo-community.org/runbot/132/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -38,7 +38,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/margin-analysis/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/margin-analysis/issues/new?body=module:%20sale_margin_sync%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/margin-analysis/issues/new?body=module:%20sale_margin_sync%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -71,6 +71,6 @@ 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 <https://github.com/OCA/margin-analysis/tree/13.0/sale_margin_sync>`_ project on GitHub.
This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/14.0/sale_margin_sync>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion sale_margin_sync/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale margin sync",
"summary": "Recompute sale margin when stock move cost price is changed",
"version": "13.0.1.0.1",
"version": "14.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/margin-analysis",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand Down
17 changes: 16 additions & 1 deletion sale_margin_sync/i18n/sale_margin_sync.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -13,6 +13,21 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_margin_sync
#: model:ir.model.fields,field_description:sale_margin_sync.field_stock_valuation_layer__display_name
msgid "Display Name"
msgstr ""

#. module: sale_margin_sync
#: model:ir.model.fields,field_description:sale_margin_sync.field_stock_valuation_layer__id
msgid "ID"
msgstr ""

#. module: sale_margin_sync
#: model:ir.model.fields,field_description:sale_margin_sync.field_stock_valuation_layer____last_update
msgid "Last Modified on"
msgstr ""

#. module: sale_margin_sync
#: model:ir.model,name:sale_margin_sync.model_stock_valuation_layer
msgid "Stock Valuation Layer"
Expand Down
9 changes: 8 additions & 1 deletion sale_margin_sync/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ def write(self, vals):
def sale_margin_sync(self):
"""Only synchronize outgoing moves"""
for svl in self.filtered(lambda l: (l.quantity < 0.0)):
svl.stock_move_id.sale_line_id.purchase_price = svl.unit_cost
sale_line_id = svl.stock_move_id.sale_line_id
product_cost = svl.unit_cost
if sale_line_id.product_uom and sale_line_id.product_uom != svl.uom_id:
product_cost = svl.uom_id._compute_price(
product_cost,
sale_line_id.product_uom,
)
sale_line_id.purchase_price = product_cost
6 changes: 3 additions & 3 deletions sale_margin_sync/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Sale margin sync</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/margin-analysis/tree/13.0/sale_margin_sync"><img alt="OCA/margin-analysis" src="https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/margin-analysis-13-0/margin-analysis-13-0-sale_margin_sync"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/132/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" 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" 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" href="https://github.com/OCA/margin-analysis/tree/14.0/sale_margin_sync"><img alt="OCA/margin-analysis" src="https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/margin-analysis-14-0/margin-analysis-14-0-sale_margin_sync"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/132/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Recompute sale margin when related stock move cost price is changed.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -386,7 +386,7 @@ <h1><a class="toc-backref" href="#id1">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 smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/margin-analysis/issues/new?body=module:%20sale_margin_sync%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/margin-analysis/issues/new?body=module:%20sale_margin_sync%0Aversion:%2014.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">
Expand Down Expand Up @@ -417,7 +417,7 @@ <h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<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>This module is part of the <a class="reference external" href="https://github.com/OCA/margin-analysis/tree/13.0/sale_margin_sync">OCA/margin-analysis</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/margin-analysis/tree/14.0/sale_margin_sync">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>
</div>
Expand Down
51 changes: 37 additions & 14 deletions sale_margin_sync/tests/test_sale_margin_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,50 @@ def setUpClass(cls):
"product_uom": cls.product.uom_id.id,
"price_unit": 100.00,
},
)
),
(
0,
0,
{
"name": cls.product.name,
"product_id": cls.product.id,
"product_uom_qty": 2,
"product_uom": cls.env.ref("uom.product_uom_dozen").id,
"price_unit": 1200.00,
},
),
],
"pricelist_id": cls.pricelist.id,
}
)

def test_sale_margin_sync(self):
self.order.action_confirm()
so_line = self.order.order_line[:1]
move = so_line.move_ids[:1]
move.quantity_done = 10
move.picking_id.action_done()
move.stock_valuation_layer_ids[:1].unit_cost = 80.0
self.assertEqual(so_line.purchase_price, 80.0)
self.assertEqual(so_line.margin, 200.0)
so_line1 = self.order.order_line[:1]
move1 = so_line1.move_ids[:1]
move1.quantity_done = 10
so_line2 = self.order.order_line[1:2]
move2 = so_line2.move_ids[:1]
move2.quantity_done = 2
self.order.picking_ids[:1]._action_done()
move1.stock_valuation_layer_ids[:1].unit_cost = 80.0
move2.stock_valuation_layer_ids[:1].unit_cost = 80.0
self.assertEqual(so_line1.purchase_price, 80.0)
self.assertEqual(so_line1.margin, 200.0)
self.assertEqual(so_line2.purchase_price, 960.0)
self.assertEqual(so_line2.margin, 480)

def test_sale_margin_sync_unvalidated_move(self):
self.order.action_confirm()
so_line = self.order.order_line[:1]
move = so_line.move_ids[:1]
move.quantity_done = 10
move.stock_valuation_layer_ids[:1].unit_cost = 80.0
self.assertEqual(so_line.purchase_price, 70.0)
self.assertEqual(so_line.margin, 300.0)
so_line1 = self.order.order_line[:1]
move1 = so_line1.move_ids[:1]
move1.quantity_done = 10
move1.stock_valuation_layer_ids[:1].unit_cost = 80.0
so_line2 = self.order.order_line[1:2]
move2 = so_line2.move_ids[:1]
move2.quantity_done = 2
move2.stock_valuation_layer_ids[:1].unit_cost = 80.0
self.assertEqual(so_line1.purchase_price, 70.0)
self.assertEqual(so_line1.margin, 300.0)
self.assertEqual(so_line2.purchase_price, 840.0)
self.assertEqual(so_line2.margin, 720)