11# Copyright 2024 ACSONE SA/NV
22# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3- from odoo .fields import Command
3+ from odoo .fields import Command , first
44
55from odoo .addons .base .tests .common import BaseCommon
66
@@ -14,12 +14,19 @@ def setUpClass(cls):
1414 cls .suppliers = cls .env .ref ("stock.stock_location_suppliers" )
1515 cls .stock = cls .env .ref ("stock.stock_location_stock" )
1616 cls .type_in = cls .env .ref ("stock.picking_type_in" )
17+ cls .type_in .allow_to_recompute_putaways = True
1718 cls .product = cls .env ["product.product" ].create (
1819 {
1920 "name" : "Test product" ,
2021 "type" : "product" ,
2122 }
2223 )
24+ cls .product_2 = cls .env ["product.product" ].create (
25+ {
26+ "name" : "Test product 2" ,
27+ "type" : "product" ,
28+ }
29+ )
2330
2431 cls .sub_location_1 = cls .location_obj .create (
2532 {
@@ -43,6 +50,16 @@ def setUpClass(cls):
4350 "location_out_id" : cls .sub_location_1 .id ,
4451 }
4552 )
53+ # Create the same rule for product 2
54+ cls .rule_2 = cls .rule_obj .create (
55+ {
56+ "product_id" : cls .product_2 .id ,
57+ "location_in_id" : cls .stock .id ,
58+ "location_out_id" : cls .sub_location_1 .id ,
59+ }
60+ )
61+
62+ cls .package = cls .env ["stock.quant.package" ].create ({})
4663
4764 def _create_picking (self ):
4865 self .picking = self .env ["stock.picking" ].create (
@@ -60,7 +77,17 @@ def _create_picking(self):
6077 "product_uom" : self .product .uom_id .id ,
6178 "product_uom_qty" : 10.0 ,
6279 }
63- )
80+ ),
81+ Command .create (
82+ {
83+ "location_id" : self .suppliers .id ,
84+ "location_dest_id" : self .stock .id ,
85+ "name" : self .product .name ,
86+ "product_id" : self .product_2 .id ,
87+ "product_uom" : self .product .uom_id .id ,
88+ "product_uom_qty" : 10.0 ,
89+ }
90+ ),
6491 ],
6592 }
6693 )
@@ -88,7 +115,7 @@ def test_recompute_putaway(self):
88115 self .picking .action_recompute_putaways ()
89116
90117 self .assertEqual (
91- self .sub_location_2 , self .picking .move_line_ids .location_dest_id
118+ self .sub_location_2 , first ( self .picking .move_line_ids ) .location_dest_id
92119 )
93120
94121 def test_recompute_putaway_line (self ):
@@ -113,7 +140,7 @@ def test_recompute_putaway_line(self):
113140 self .picking .move_line_ids .action_recompute_putaways ()
114141
115142 self .assertEqual (
116- self .sub_location_2 , self .picking .move_line_ids .location_dest_id
143+ self .sub_location_2 , first ( self .picking .move_line_ids ) .location_dest_id
117144 )
118145
119146 def test_recompute_putaway_qty_done (self ):
@@ -202,16 +229,67 @@ def test_line_can_recompute(self):
202229 picking1 = self ._create_picking ()
203230 self .picking .action_confirm ()
204231
205- self .assertTrue (self .picking .move_line_ids .can_recompute_putaways )
232+ self .assertEqual (
233+ [True , True ], self .picking .move_line_ids .mapped ("can_recompute_putaways" )
234+ )
206235
207236 picking2 = self ._create_picking ()
208237 self .picking .action_confirm ()
209- move_lines = (picking1 | picking2 ).move_line_ids
210- self .assertEqual ([True , True ], move_lines .mapped ("can_recompute_putaways" ))
238+ move_lines_picking1 = picking1 .move_line_ids
239+ self .assertEqual (
240+ [True , True ], move_lines_picking1 .mapped ("can_recompute_putaways" )
241+ )
242+
243+ move_lines_picking2 = picking2 .move_line_ids
244+ self .assertEqual (
245+ [True , True ], move_lines_picking2 .mapped ("can_recompute_putaways" )
246+ )
211247
212248 picking1 .printed = True
213- self .assertEqual ([False , True ], move_lines .mapped ("can_recompute_putaways" ))
249+ move_lines_picking1 = picking1 .move_line_ids
250+ self .assertEqual (
251+ [False , False ], move_lines_picking1 .mapped ("can_recompute_putaways" )
252+ )
253+ move_lines_picking2 = picking2 .move_line_ids
254+ self .assertEqual (
255+ [True , True ], move_lines_picking2 .mapped ("can_recompute_putaways" )
256+ )
214257
215258 picking1 .printed = False
216259 picking2 .move_line_ids .qty_done = 10.0
217- self .assertEqual ([True , False ], move_lines .mapped ("can_recompute_putaways" ))
260+ move_lines_picking1 = picking1 .move_line_ids
261+ self .assertEqual (
262+ [True , True ], move_lines_picking1 .mapped ("can_recompute_putaways" )
263+ )
264+ move_lines_picking2 = picking2 .move_line_ids
265+ self .assertEqual (
266+ [False , False ], move_lines_picking2 .mapped ("can_recompute_putaways" )
267+ )
268+
269+ def test_recompute_putaway_packaging (self ):
270+ """
271+ Create a single picking from Suppliers -> Stock
272+ The created operation point to the Sub location 1
273+ Change the rule to point to Sub location 2
274+ Launch the acdtion to recompute putaways
275+ The operation point to the Sub location 2
276+ """
277+ self ._create_picking ()
278+ self .picking .action_confirm ()
279+
280+ self .assertTrue (self .picking .move_line_ids )
281+ self .assertEqual (
282+ self .sub_location_1 , self .picking .move_line_ids .location_dest_id
283+ )
284+
285+ # Simulate the package is already set
286+ self .picking .move_line_ids .result_package_id = self .package
287+
288+ # Change the rule destination
289+ self .rule .location_out_id = self .sub_location_2
290+
291+ self .picking .action_recompute_putaways ()
292+
293+ self .assertEqual (
294+ self .sub_location_1 , self .picking .move_line_ids .location_dest_id
295+ )
0 commit comments