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 )
0 commit comments