Skip to content

Commit 6b9930e

Browse files
[MIG] sale_margin_delivered: Migration to 17.0
1 parent 03562e3 commit 6b9930e

9 files changed

Lines changed: 39 additions & 64 deletions

File tree

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class SaleOrderLine(models.Model):
1818
margin_delivered_percent = fields.Float(
1919
compute="_compute_margin_delivered",
2020
store=True,
21-
readonly=True,
2221
help="Margin percent between the Unit Price with discounts and "
2322
"Delivered Unit Cost.\n\n"
2423
"Formula: ((Unit Price with Discounts - Average Unit Cost of "
@@ -81,7 +80,10 @@ def _compute_margin_delivered(self):
8180
)
8281

8382
if line.product_id.type != "product":
84-
currency = line.order_id.pricelist_id.currency_id
83+
currency = (
84+
line.order_id.pricelist_id.currency_id
85+
or line.company_id.currency_id
86+
)
8587
price = line.purchase_price
8688
line.margin_delivered = currency.round(
8789
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: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
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 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()
13-
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
1413
cls.SaleOrder = cls.env["sale.order"]
1514
cls.product_uom_id = cls.env.ref("uom.product_uom_unit")
1615
cls.product = cls.env["product.product"].create(
@@ -28,9 +27,7 @@ def setUpClass(cls):
2827
{
2928
"name": "Test pricelist",
3029
"item_ids": [
31-
(
32-
0,
33-
0,
30+
Command.create(
3431
{
3532
"applied_on": "3_global",
3633
"compute_price": "formula",
@@ -66,9 +63,7 @@ def get_return_picking_wizard(self, picking):
6663
"""Returns the wizard to create a return picking"""
6764
stock_return_picking_form = Form(
6865
self.env["stock.return.picking"].with_context(
69-
active_ids=picking.ids,
70-
active_id=picking.ids[0],
71-
active_model="stock.picking",
66+
default_picking_id=picking.id,
7267
)
7368
)
7469
return stock_return_picking_form.save()
@@ -87,8 +82,8 @@ def test_sale_margin_delivered(self):
8782
sale_order.action_confirm()
8883
picking = sale_order.picking_ids
8984
picking.action_assign()
90-
picking.move_line_ids.qty_done = 3.0
91-
picking._action_done()
85+
picking.move_ids.quantity = 3.0
86+
picking.with_context(skip_backorder=True).button_validate()
9287
order_line = sale_order.order_line[:1]
9388
self.assertEqual(order_line.margin_delivered, 30.0)
9489
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -100,8 +95,8 @@ def test_sale_margin_delivered_excess(self):
10095
sale_order.action_confirm()
10196
picking = sale_order.picking_ids
10297
picking.action_assign()
103-
picking.move_line_ids.qty_done = 12.0
104-
picking._action_done()
98+
picking.move_line_ids.quantity = 12.0
99+
picking.with_context(skip_backorder=True).button_validate()
105100
order_line = sale_order.order_line[:1]
106101
self.assertEqual(order_line.margin_delivered, 120.0)
107102
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -121,15 +116,15 @@ def _create_return(self, picking, qty_refund=3.0, to_refund=False):
121116
return_wiz.product_return_moves.write(
122117
{"quantity": qty_refund, "to_refund": to_refund}
123118
)
124-
new_picking_id, pick_type_id = return_wiz._create_returns()
125-
return self.env["stock.picking"].browse(new_picking_id)
119+
res = return_wiz.create_returns()
120+
return self.env["stock.picking"].browse(res["res_id"])
126121

127122
def _validate_so_picking(self, sale_order, qty_done=6.0):
128123
"""Validate picking"""
129124
picking = sale_order.picking_ids
130125
picking.action_assign()
131-
picking.move_line_ids.qty_done = qty_done
132-
picking._action_done()
126+
picking.move_line_ids.quantity = qty_done
127+
picking.with_context(skip_backorder=True).button_validate()
133128
return picking
134129

135130
def test_sale_margin_delivered_return_to_refund(self):
@@ -138,8 +133,8 @@ def test_sale_margin_delivered_return_to_refund(self):
138133
sale_order.action_confirm()
139134
picking = self._validate_so_picking(sale_order, qty_done=6.0)
140135
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()
136+
picking_return.move_line_ids.quantity = 3.0
137+
picking_return.with_context(skip_backorder=True).button_validate()
143138
order_line = sale_order.order_line[:1]
144139
self.assertEqual(order_line.margin_delivered, 30.0)
145140
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -151,8 +146,8 @@ def test_sale_margin_delivered_return_to_refund_excess(self):
151146
sale_order.action_confirm()
152147
picking = self._validate_so_picking(sale_order, qty_done=12.0)
153148
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()
149+
picking_return.move_line_ids.quantity = 3.0
150+
picking_return.with_context(skip_backorder=True).button_validate()
156151
order_line = sale_order.order_line[:1]
157152
self.assertEqual(order_line.margin_delivered, 90.0)
158153
self.assertEqual(order_line.margin_delivered_percent, 0.5)
@@ -164,7 +159,7 @@ def test_sale_margin_delivered_return_no_refund(self):
164159
sale_order.action_confirm()
165160
picking = self._validate_so_picking(sale_order, qty_done=6.0)
166161
picking_return = self._create_return(picking, qty_refund=3.0, to_refund=False)
167-
picking_return.move_line_ids.qty_done = 3.0
162+
picking_return.move_line_ids.quantity = 3.0
168163
picking_return._action_done()
169164
order_line = sale_order.order_line[:1]
170165
self.assertEqual(order_line.margin_delivered, 60.0)
@@ -177,7 +172,7 @@ def test_sale_margin_delivered_return_no_refund_excess(self):
177172
sale_order.action_confirm()
178173
picking = self._validate_so_picking(sale_order, qty_done=12.0)
179174
picking_return = self._create_return(picking, qty_refund=3.0, to_refund=False)
180-
picking_return.move_line_ids.qty_done = 3.0
175+
picking_return.move_line_ids.quantity = 3.0
181176
picking_return._action_done()
182177
order_line = sale_order.order_line[:1]
183178
self.assertEqual(order_line.margin_delivered, 120.0)
@@ -192,8 +187,8 @@ def test_sale_margin_delivered_precision(self):
192187
sale_order.action_confirm()
193188
picking = sale_order.picking_ids
194189
picking.action_assign()
195-
picking.move_line_ids.qty_done = 6.0
196-
picking._action_done()
190+
picking.move_line_ids.quantity = 6.0
191+
picking.with_context(skip_backorder=True).button_validate()
197192
order_line = sale_order.order_line[:1]
198193
# price_subtotal is rounded
199194
self.assertEqual(order_line.price_subtotal, 100.45)
@@ -212,8 +207,8 @@ def test_sale_margin_no_cost(self):
212207
sale_order.action_confirm()
213208
picking = sale_order.picking_ids
214209
picking.action_assign()
215-
picking.move_line_ids.qty_done = 6.0
216-
picking._action_done()
210+
picking.move_line_ids.quantity = 6.0
211+
picking.with_context(skip_backorder=True).button_validate()
217212
order_line = sale_order.order_line[:1]
218213
# price_subtotal is rounded
219214
self.assertEqual(order_line.margin_delivered, 120)

sale_margin_delivered/views/sale_margin_delivered_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
name="margin_delivered_percent"
1717
string="Margin dlvd. (%)"
1818
optional="hide"
19-
attrs="{'invisible': [('price_subtotal', '=', 0)]}"
19+
invisible="not price_subtotal"
2020
widget="percentage"
2121
/>
2222
<field name="margin_delivered" string="Margin dlvd." optional="hide" />

0 commit comments

Comments
 (0)