From b6c0b55af42f11f2b2ff9a7cca4335adbf5d0c89 Mon Sep 17 00:00:00 2001 From: hveficent Date: Wed, 26 Feb 2020 10:57:03 +0100 Subject: [PATCH] [FIX] stock_move_location: Error on onchange origin location --- stock_move_location/readme/CONTRIBUTORS.rst | 1 + stock_move_location/tests/test_common.py | 19 +++++++++++++++++++ .../tests/test_move_location.py | 15 +++++++++++++++ .../wizard/stock_move_location.py | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/stock_move_location/readme/CONTRIBUTORS.rst b/stock_move_location/readme/CONTRIBUTORS.rst index bb0536766..22ce18c67 100644 --- a/stock_move_location/readme/CONTRIBUTORS.rst +++ b/stock_move_location/readme/CONTRIBUTORS.rst @@ -4,3 +4,4 @@ * Joan Sisquella * Jordi Ballester Alomar * Lois Rilo +* Héctor Villarreal diff --git a/stock_move_location/tests/test_common.py b/stock_move_location/tests/test_common.py index 21da35c5f..8877f2537 100644 --- a/stock_move_location/tests/test_common.py +++ b/stock_move_location/tests/test_common.py @@ -32,6 +32,15 @@ class TestsCommon(common.SavepointCase): "company_id": cls.company.id, } ) + cls.internal_loc_2_shelf = cls.location_obj.create( + { + "name": "Shelf", + "usage": "internal", + "active": True, + "company_id": cls.company.id, + "location_id": cls.internal_loc_2.id, + } + ) cls.uom_unit = cls.env.ref("uom.product_uom_unit") cls.product_no_lots = product_obj.create( {"name": "Pineapple", "type": "product", "tracking": "none"} @@ -94,3 +103,13 @@ class TestsCommon(common.SavepointCase): "destination_location_id": destination_location.id, } ) + + def _create_putaway_for_product(self, product, loc_in, loc_out): + putaway = self.env["stock.putaway.rule"].create( + { + "product_id": product.id, + "location_in_id": loc_in.id, + "location_out_id": loc_out.id, + } + ) + loc_in.write({"putaway_rule_ids": [(4, putaway.id, 0)]}) diff --git a/stock_move_location/tests/test_move_location.py b/stock_move_location/tests/test_move_location.py index 8e1a9d93e..e9b65a455 100644 --- a/stock_move_location/tests/test_move_location.py +++ b/stock_move_location/tests/test_move_location.py @@ -117,3 +117,18 @@ class TestMoveLocation(TestsCommon): """Test that no error is raised from actions.""" pick_type = self.env.ref("stock.picking_type_internal") pick_type.action_move_location() + + def test_wizard_with_putaway_strategy(self): + """Test that Putaway strategies are being applied.""" + self._create_putaway_for_product( + self.product_no_lots, self.internal_loc_2, self.internal_loc_2_shelf + ) + wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) + wizard.apply_putaway_strategy = True + wizard.onchange_origin_location() + putaway_line = wizard.stock_move_location_line_ids.filtered( + lambda p: p.product_id == self.product_no_lots + )[0] + self.assertEqual( + putaway_line.destination_location_id, self.internal_loc_2_shelf + ) diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index d67373985..f6ea3b59c 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -211,7 +211,7 @@ class StockMoveLocationWizard(models.TransientModel): # Apply the putaway strategy location_dest_id = ( self.apply_putaway_strategy - and self.destination_location_id.get_putaway_strategy(product).id + and self.destination_location_id._get_putaway_strategy(product).id or self.destination_location_id.id ) product_data.append(