From 5f7648bb9a3baaf21230051c19113dbfb8e6966d Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Mon, 2 Sep 2019 13:00:00 +0000 Subject: [PATCH] [FIX] mrp: failing test multi mrp step It's due to MRP refactoring that confirm raw moves before finished moves. It implies that in _assign picking, SFP with final product will search a picking but the stock.move do not have a created_production_id and it will be merged inside the intermediate SFP (it works before because it was the intermediate SFP that was merged in the finished SFP). _key_assign_picking is also added if multiple moves are confirmed w/ and w/h created_production_id, we won't merge them in the same picking. closes odoo/odoo#36335 Signed-off-by: Christophe Simonis --- addons/mrp/models/stock_move.py | 7 ++++-- .../test_warehouse_multistep_manufacturing.py | 23 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index d0ef5bf3637..8d8dcc3de26 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -233,10 +233,13 @@ class StockMove(models.Model): res = super(StockMove, self)._should_be_assigned() return bool(res and not (self.production_id or self.raw_material_production_id)) + def _key_assign_picking(self): + keys = super(StockMove, self)._key_assign_picking() + return keys + (self.created_production_id,) + def _search_picking_for_assignation_domain(self): res = super(StockMove, self)._search_picking_for_assignation_domain() - if self.created_production_id: - res.append(('move_lines.created_production_id', '=', self.created_production_id.id)) + res.append(('move_lines.created_production_id', '=', self.created_production_id.id)) return res def _compute_kit_quantities(self, product_id, kit_qty, kit_bom, filters): diff --git a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py index 7367d818bd2..37bf6ee7f7e 100644 --- a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py +++ b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py @@ -165,6 +165,7 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): production_form.product_id = self.complex_product production_form.picking_type_id = self.warehouse.manu_type_id production = production_form.save() + production.action_confirm() move_raw_ids = production.move_raw_ids self.assertEqual(len(move_raw_ids), 2) @@ -197,23 +198,31 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): # Picking: SFP PostProcessing -> Stock ## Stick from Subprocess - picking = pickings[1] + picking = self.env['stock.picking'].search([ + ('move_lines.product_id', '=', self.finished_product.id), + ('location_dest_id', '=', self.warehouse.lot_stock_id.id), + ('group_id', '=', production.procurement_group_id.id) + ]) self.assertEqual(len(picking.move_lines), 1) - picking.product_id = self.finished_product # Picking: PC Stock -> Preprocessing ## Stick ## Raw Iron - picking = pickings[0] + picking = self.env['stock.picking'].search([ + ('move_lines.product_id', 'in', [self.finished_product.id, self.raw_product_2.id]), + ('location_id', '=', self.warehouse.lot_stock_id.id), + ('group_id', '=', production.procurement_group_id.id) + ]) self.assertEqual(len(picking.move_lines), 2) - picking.move_lines[0].product_id = self.finished_product - picking.move_lines[1].product_id = self.raw_product_2 # Picking: SFP PostProcessing -> Stock ## Arrow from this process - picking = pickings[2] + picking = picking = self.env['stock.picking'].search([ + ('move_lines.product_id', '=', self.complex_product.id), + ('location_dest_id', '=', self.warehouse.lot_stock_id.id), + ('group_id', '=', production.procurement_group_id.id) + ]) self.assertEqual(len(picking.move_lines), 1) - picking.product_id = self.complex_product def test_manufacturing_flow(self):