From abb4b142ea8bb569d6b3c823764ef4ba02de047d Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Fri, 19 Oct 2018 08:39:34 +0000 Subject: [PATCH] [FIX] mrp: duplicate raw moves Usecase to reproduce - Enable multi locations, multi routes - Check mrp 3 steps on warehouse - Create a MO Raw moves are duplicated. It happens due to commit aeb038747f8221dd8ca82c08b704b78c247f1173 The purpose of the commit was to split the rules from SAM to stock. The pull rule should be in manufacture route and the push rule on the warehouse. However the push rule was not correctly copied and created a push rule from prod to sam instead of sam to stock. Fixes #27962 closes odoo/odoo#27965 --- addons/mrp/models/stock_warehouse.py | 2 +- .../test_warehouse_multistep_manufacturing.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/stock_warehouse.py b/addons/mrp/models/stock_warehouse.py index cff6ea9fe41..2bb5f5f8d76 100644 --- a/addons/mrp/models/stock_warehouse.py +++ b/addons/mrp/models/stock_warehouse.py @@ -52,7 +52,7 @@ class StockWarehouse(models.Model): 'pbm_sam': [ self.Routing(warehouse.lot_stock_id, warehouse.pbm_loc_id, warehouse.pbm_type_id, 'pull'), self.Routing(warehouse.pbm_loc_id, production_location_id, warehouse.manu_type_id, 'pull'), - self.Routing(production_location_id, warehouse.sam_loc_id, warehouse.sam_type_id, 'push'), + self.Routing(warehouse.sam_loc_id, warehouse.lot_stock_id, warehouse.sam_type_id, 'push'), ], }) return result diff --git a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py index 08bce4479b3..bf1195fdaf0 100644 --- a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py +++ b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py @@ -86,6 +86,41 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 3) self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id, self.warehouse.sam_loc_id.id) + def test_manufacturing_3_steps(self): + """ Test MO/picking before manufacturing/picking after manufacturing + components and move_orig/move_dest. Ensure that everything is created + correctly. + """ + with Form(self.warehouse) as warehouse: + warehouse.manufacture_steps = 'pbm_sam' + + production_form = Form(self.env['mrp.production']) + production_form.product_id = self.finished_product + production_form.picking_type_id = self.warehouse.manu_type_id + production = production_form.save() + + move_raw_ids = production.move_raw_ids + self.assertEqual(len(move_raw_ids), 1) + self.assertEqual(move_raw_ids.product_id, self.raw_product) + self.assertEqual(move_raw_ids.picking_type_id, self.warehouse.manu_type_id) + pbm_move = move_raw_ids.move_orig_ids + self.assertEqual(len(pbm_move), 1) + self.assertEqual(pbm_move.location_id, self.warehouse.lot_stock_id) + self.assertEqual(pbm_move.location_dest_id, self.warehouse.pbm_loc_id) + self.assertEqual(pbm_move.picking_type_id, self.warehouse.pbm_type_id) + self.assertFalse(pbm_move.move_orig_ids) + + move_finished_ids = production.move_finished_ids + self.assertEqual(len(move_finished_ids), 1) + self.assertEqual(move_finished_ids.product_id, self.finished_product) + self.assertEqual(move_finished_ids.picking_type_id, self.warehouse.manu_type_id) + sam_move = move_finished_ids.move_dest_ids + self.assertEqual(len(sam_move), 1) + self.assertEqual(sam_move.location_id, self.warehouse.sam_loc_id) + self.assertEqual(sam_move.location_dest_id, self.warehouse.lot_stock_id) + self.assertEqual(sam_move.picking_type_id, self.warehouse.sam_type_id) + self.assertFalse(sam_move.move_dest_ids) + def test_manufacturing_flow(self): """ Simulate a pick pack ship delivery combined with a picking before manufacturing and store after manufacturing. Also ensure that the MO and