Skip to content

Commit e5ed3ee

Browse files
committed
[IMP] stock_picking_putaway_recompute: Don't authorize recompute with packages
As soon as there is a result package for the operation, the destination location recomputation is not authorized as all operations contained in a package should go to the same destination.
1 parent e42d350 commit e5ed3ee

File tree

5 files changed

+94
-12
lines changed

5 files changed

+94
-12
lines changed

stock_picking_putaway_recompute/README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ Usage
6464
- If a putaway rule has been changed after product reservation, click
6565
on the button 'Recompute putaways'. This will recompute the
6666
destination locations on all detailed operations that have no done
67-
quantity yet.
67+
quantity yet and no result package (as all operations for the same
68+
package should go to the same destination).
6869
- Moreover, the action is available on picking level and on detailed
6970
operation one too.
7071

stock_picking_putaway_recompute/models/stock_move_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def _filtered_for_putaway_recompute(self) -> Self:
3434
return self.filtered(
3535
lambda line: line.picking_type_id.allow_to_recompute_putaways
3636
and not line.picking_id.printed
37+
and not line.result_package_id
3738
and not line.qty_done
3839
)
3940

stock_picking_putaway_recompute/readme/USAGE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
enabled.
44
- If a putaway rule has been changed after product reservation, click on
55
the button 'Recompute putaways'. This will recompute the destination locations
6-
on all detailed operations that have no done quantity yet.
6+
on all detailed operations that have no done quantity yet and no result package
7+
(as all operations for the same package should go to the same destination).
78
- Moreover, the action is available on picking level and on detailed operation one too.

stock_picking_putaway_recompute/static/description/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
413413
<li>If a putaway rule has been changed after product reservation, click
414414
on the button ‘Recompute putaways’. This will recompute the
415415
destination locations on all detailed operations that have no done
416-
quantity yet.</li>
416+
quantity yet and no result package (as all operations for the same
417+
package should go to the same destination).</li>
417418
<li>Moreover, the action is available on picking level and on detailed
418419
operation one too.</li>
419420
</ul>

stock_picking_putaway_recompute/tests/test_recompute_putaway.py

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

55
from 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

Comments
 (0)