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