Skip to content

Commit

Permalink
[IMP] stock_picking_putaway_recompute: Don't authorize recompute with…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
rousseldenis committed Oct 10, 2024
1 parent e42d350 commit e5ed3ee
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 12 deletions.
3 changes: 2 additions & 1 deletion stock_picking_putaway_recompute/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Usage
- If a putaway rule has been changed after product reservation, click
on the button 'Recompute putaways'. This will recompute the
destination locations on all detailed operations that have no done
quantity yet.
quantity yet and no result package (as all operations for the same
package should go to the same destination).
- Moreover, the action is available on picking level and on detailed
operation one too.

Expand Down
1 change: 1 addition & 0 deletions stock_picking_putaway_recompute/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _filtered_for_putaway_recompute(self) -> Self:
return self.filtered(
lambda line: line.picking_type_id.allow_to_recompute_putaways
and not line.picking_id.printed
and not line.result_package_id
and not line.qty_done
)

Expand Down
3 changes: 2 additions & 1 deletion stock_picking_putaway_recompute/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
enabled.
- If a putaway rule has been changed after product reservation, click on
the button 'Recompute putaways'. This will recompute the destination locations
on all detailed operations that have no done quantity yet.
on all detailed operations that have no done quantity yet and no result package
(as all operations for the same package should go to the same destination).
- Moreover, the action is available on picking level and on detailed operation one too.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<li>If a putaway rule has been changed after product reservation, click
on the button ‘Recompute putaways’. This will recompute the
destination locations on all detailed operations that have no done
quantity yet.</li>
quantity yet and no result package (as all operations for the same
package should go to the same destination).</li>
<li>Moreover, the action is available on picking level and on detailed
operation one too.</li>
</ul>
Expand Down
96 changes: 87 additions & 9 deletions stock_picking_putaway_recompute/tests/test_recompute_putaway.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.fields import Command
from odoo.fields import Command, first

from odoo.addons.base.tests.common import BaseCommon

Expand All @@ -14,12 +14,19 @@ def setUpClass(cls):
cls.suppliers = cls.env.ref("stock.stock_location_suppliers")
cls.stock = cls.env.ref("stock.stock_location_stock")
cls.type_in = cls.env.ref("stock.picking_type_in")
cls.type_in.allow_to_recompute_putaways = True
cls.product = cls.env["product.product"].create(
{
"name": "Test product",
"type": "product",
}
)
cls.product_2 = cls.env["product.product"].create(
{
"name": "Test product 2",
"type": "product",
}
)

cls.sub_location_1 = cls.location_obj.create(
{
Expand All @@ -43,6 +50,16 @@ def setUpClass(cls):
"location_out_id": cls.sub_location_1.id,
}
)
# Create the same rule for product 2
cls.rule_2 = cls.rule_obj.create(
{
"product_id": cls.product_2.id,
"location_in_id": cls.stock.id,
"location_out_id": cls.sub_location_1.id,
}
)

cls.package = cls.env["stock.quant.package"].create({})

def _create_picking(self):
self.picking = self.env["stock.picking"].create(
Expand All @@ -60,7 +77,17 @@ def _create_picking(self):
"product_uom": self.product.uom_id.id,
"product_uom_qty": 10.0,
}
)
),
Command.create(
{
"location_id": self.suppliers.id,
"location_dest_id": self.stock.id,
"name": self.product.name,
"product_id": self.product_2.id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 10.0,
}
),
],
}
)
Expand Down Expand Up @@ -88,7 +115,7 @@ def test_recompute_putaway(self):
self.picking.action_recompute_putaways()

self.assertEqual(
self.sub_location_2, self.picking.move_line_ids.location_dest_id
self.sub_location_2, first(self.picking.move_line_ids).location_dest_id
)

def test_recompute_putaway_line(self):
Expand All @@ -113,7 +140,7 @@ def test_recompute_putaway_line(self):
self.picking.move_line_ids.action_recompute_putaways()

self.assertEqual(
self.sub_location_2, self.picking.move_line_ids.location_dest_id
self.sub_location_2, first(self.picking.move_line_ids).location_dest_id
)

def test_recompute_putaway_qty_done(self):
Expand Down Expand Up @@ -202,16 +229,67 @@ def test_line_can_recompute(self):
picking1 = self._create_picking()
self.picking.action_confirm()

self.assertTrue(self.picking.move_line_ids.can_recompute_putaways)
self.assertEqual(
[True, True], self.picking.move_line_ids.mapped("can_recompute_putaways")
)

picking2 = self._create_picking()
self.picking.action_confirm()
move_lines = (picking1 | picking2).move_line_ids
self.assertEqual([True, True], move_lines.mapped("can_recompute_putaways"))
move_lines_picking1 = picking1.move_line_ids
self.assertEqual(
[True, True], move_lines_picking1.mapped("can_recompute_putaways")
)

move_lines_picking2 = picking2.move_line_ids
self.assertEqual(
[True, True], move_lines_picking2.mapped("can_recompute_putaways")
)

picking1.printed = True
self.assertEqual([False, True], move_lines.mapped("can_recompute_putaways"))
move_lines_picking1 = picking1.move_line_ids
self.assertEqual(
[False, False], move_lines_picking1.mapped("can_recompute_putaways")
)
move_lines_picking2 = picking2.move_line_ids
self.assertEqual(
[True, True], move_lines_picking2.mapped("can_recompute_putaways")
)

picking1.printed = False
picking2.move_line_ids.qty_done = 10.0
self.assertEqual([True, False], move_lines.mapped("can_recompute_putaways"))
move_lines_picking1 = picking1.move_line_ids
self.assertEqual(
[True, True], move_lines_picking1.mapped("can_recompute_putaways")
)
move_lines_picking2 = picking2.move_line_ids
self.assertEqual(
[False, False], move_lines_picking2.mapped("can_recompute_putaways")
)

def test_recompute_putaway_packaging(self):
"""
Create a single picking from Suppliers -> Stock
The created operation point to the Sub location 1
Change the rule to point to Sub location 2
Launch the acdtion to recompute putaways
The operation point to the Sub location 2
"""
self._create_picking()
self.picking.action_confirm()

self.assertTrue(self.picking.move_line_ids)
self.assertEqual(
self.sub_location_1, self.picking.move_line_ids.location_dest_id
)

# Simulate the package is already set
self.picking.move_line_ids.result_package_id = self.package

# Change the rule destination
self.rule.location_out_id = self.sub_location_2

self.picking.action_recompute_putaways()

self.assertEqual(
self.sub_location_1, self.picking.move_line_ids.location_dest_id
)

0 comments on commit e5ed3ee

Please sign in to comment.