Skip to content

Commit e4e13bf

Browse files
[MIG] sale_margin_delivered: Migration to 17.0
1 parent e046396 commit e4e13bf

File tree

8 files changed

+37
-58
lines changed

8 files changed

+37
-58
lines changed

sale_margin_delivered/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ Contributors
105105

106106
- Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)
107107
- Rafael Blasco (`Moduon <https://www.moduon.team/>`__)
108+
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__
109+
110+
- Bhavesh Heliconia
108111

109112
Maintainers
110113
-----------

sale_margin_delivered/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
{
44
"name": "Sale Margin Delivered",
5-
"version": "16.0.2.0.0",
5+
"version": "17.0.1.0.0",
66
"author": "Tecnativa, Odoo Community Association (OCA)",
77
"website": "https://github.com/OCA/margin-analysis",
88
"category": "Sales",

sale_margin_delivered/migrations/16.0.1.0.0/post-migration.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

sale_margin_delivered/migrations/16.0.2.0.0/post-migration.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

sale_margin_delivered/models/sale_margin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def _compute_margin_delivered(self):
8181
)
8282

8383
if line.product_id.type != "product":
84-
currency = line.order_id.pricelist_id.currency_id
84+
currency = (
85+
line.order_id.pricelist_id.currency_id
86+
or line.company_id.currency_id
87+
)
8588
price = line.purchase_price
8689
line.margin_delivered = currency.round(
8790
line.price_subtotal - (price * line.qty_delivered)

sale_margin_delivered/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
- Pilar Vargas
66
- Eduardo de Miguel ([Moduon](https://www.moduon.team/))
77
- Rafael Blasco ([Moduon](https://www.moduon.team/))
8+
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
9+
- Bhavesh Heliconia

sale_margin_delivered/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
448448
</li>
449449
<li>Eduardo de Miguel (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
450450
<li>Rafael Blasco (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
451+
<li><a class="reference external" href="https://www.heliconia.io">Heliconia Solutions Pvt. Ltd.</a><ul>
452+
<li>Bhavesh Heliconia</li>
453+
</ul>
454+
</li>
451455
</ul>
452456
</div>
453457
<div class="section" id="maintainers">

sale_margin_delivered/tests/test_sale_margin_delivered.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright 2019 Tecnativa - Sergio Teruel
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl
3+
from odoo import Command
4+
from odoo.tests import Form
35

4-
from odoo.tests import Form, TransactionCase
6+
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT, BaseCommon
57

6-
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
78

8-
9-
class TestSaleMarginDelivered(TransactionCase):
9+
class TestSaleMarginDelivered(BaseCommon):
1010
@classmethod
1111
def setUpClass(cls):
1212
super().setUpClass()
@@ -28,9 +28,7 @@ def setUpClass(cls):
2828
{
2929
"name": "Test pricelist",
3030
"item_ids": [
31-
(
32-
0,
33-
0,
31+
Command.create(
3432
{
3533
"applied_on": "3_global",
3634
"compute_price": "formula",
@@ -87,8 +85,8 @@ def test_sale_margin_delivered(self):
8785
sale_order.action_confirm()
8886
picking = sale_order.picking_ids
8987
picking.action_assign()
90-
picking.move_line_ids.qty_done = 3.0
91-
picking._action_done()
88+
picking.move_ids.quantity = 3.0
89+
picking.with_context(skip_backorder=True).button_validate()
9290
order_line = sale_order.order_line[:1]
9391
self.assertEqual(order_line.margin_delivered, 30.0)
9492
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -100,8 +98,8 @@ def test_sale_margin_delivered_excess(self):
10098
sale_order.action_confirm()
10199
picking = sale_order.picking_ids
102100
picking.action_assign()
103-
picking.move_line_ids.qty_done = 12.0
104-
picking._action_done()
101+
picking.move_line_ids.quantity = 12.0
102+
picking.with_context(skip_backorder=True).button_validate()
105103
order_line = sale_order.order_line[:1]
106104
self.assertEqual(order_line.margin_delivered, 120.0)
107105
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -121,15 +119,15 @@ def _create_return(self, picking, qty_refund=3.0, to_refund=False):
121119
return_wiz.product_return_moves.write(
122120
{"quantity": qty_refund, "to_refund": to_refund}
123121
)
124-
new_picking_id, pick_type_id = return_wiz._create_returns()
125-
return self.env["stock.picking"].browse(new_picking_id)
122+
res = return_wiz.create_returns()
123+
return self.env["stock.picking"].browse(res["res_id"])
126124

127125
def _validate_so_picking(self, sale_order, qty_done=6.0):
128126
"""Validate picking"""
129127
picking = sale_order.picking_ids
130128
picking.action_assign()
131-
picking.move_line_ids.qty_done = qty_done
132-
picking._action_done()
129+
picking.move_line_ids.quantity = qty_done
130+
picking.with_context(skip_backorder=True).button_validate()
133131
return picking
134132

135133
def test_sale_margin_delivered_return_to_refund(self):
@@ -138,8 +136,8 @@ def test_sale_margin_delivered_return_to_refund(self):
138136
sale_order.action_confirm()
139137
picking = self._validate_so_picking(sale_order, qty_done=6.0)
140138
picking_return = self._create_return(picking, qty_refund=3.0, to_refund=True)
141-
picking_return.move_line_ids.qty_done = 3.0
142-
picking_return._action_done()
139+
picking_return.move_line_ids.quantity = 3.0
140+
picking_return.with_context(skip_backorder=True).button_validate()
143141
order_line = sale_order.order_line[:1]
144142
self.assertEqual(order_line.margin_delivered, 30.0)
145143
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -151,8 +149,8 @@ def test_sale_margin_delivered_return_to_refund_excess(self):
151149
sale_order.action_confirm()
152150
picking = self._validate_so_picking(sale_order, qty_done=12.0)
153151
picking_return = self._create_return(picking, qty_refund=3.0, to_refund=True)
154-
picking_return.move_line_ids.qty_done = 3.0
155-
picking_return._action_done()
152+
picking_return.move_line_ids.quantity = 3.0
153+
picking_return.with_context(skip_backorder=True).button_validate()
156154
order_line = sale_order.order_line[:1]
157155
self.assertEqual(order_line.margin_delivered, 90.0)
158156
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -164,7 +162,7 @@ def test_sale_margin_delivered_return_no_refund(self):
164162
sale_order.action_confirm()
165163
picking = self._validate_so_picking(sale_order, qty_done=6.0)
166164
picking_return = self._create_return(picking, qty_refund=3.0, to_refund=False)
167-
picking_return.move_line_ids.qty_done = 3.0
165+
picking_return.move_line_ids.quantity = 3.0
168166
picking_return._action_done()
169167
order_line = sale_order.order_line[:1]
170168
self.assertEqual(order_line.margin_delivered, 60.0)
@@ -177,7 +175,7 @@ def test_sale_margin_delivered_return_no_refund_excess(self):
177175
sale_order.action_confirm()
178176
picking = self._validate_so_picking(sale_order, qty_done=12.0)
179177
picking_return = self._create_return(picking, qty_refund=3.0, to_refund=False)
180-
picking_return.move_line_ids.qty_done = 3.0
178+
picking_return.move_line_ids.quantity = 3.0
181179
picking_return._action_done()
182180
order_line = sale_order.order_line[:1]
183181
self.assertEqual(order_line.margin_delivered, 120.0)
@@ -192,8 +190,8 @@ def test_sale_margin_delivered_precision(self):
192190
sale_order.action_confirm()
193191
picking = sale_order.picking_ids
194192
picking.action_assign()
195-
picking.move_line_ids.qty_done = 6.0
196-
picking._action_done()
193+
picking.move_line_ids.quantity = 6.0
194+
picking.with_context(skip_backorder=True).button_validate()
197195
order_line = sale_order.order_line[:1]
198196
# price_subtotal is rounded
199197
self.assertEqual(order_line.price_subtotal, 100.45)
@@ -212,8 +210,8 @@ def test_sale_margin_no_cost(self):
212210
sale_order.action_confirm()
213211
picking = sale_order.picking_ids
214212
picking.action_assign()
215-
picking.move_line_ids.qty_done = 6.0
216-
picking._action_done()
213+
picking.move_line_ids.quantity = 6.0
214+
picking.with_context(skip_backorder=True).button_validate()
217215
order_line = sale_order.order_line[:1]
218216
# price_subtotal is rounded
219217
self.assertEqual(order_line.margin_delivered, 120)

0 commit comments

Comments
 (0)