diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 7185a4248cb..14484e5eced 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -2028,10 +2028,10 @@ class MrpProduction(models.Model): for move in self.move_finished_ids: dests.setdefault(move.byproduct_id.id, []).extend(move.move_dest_ids.ids) - production = self.env['mrp.production'].create({ + production = self.env['mrp.production'].with_context(default_picking_type_id=self.picking_type_id.id).create({ 'product_id': product_id.id, 'bom_id': bom_id.id, - 'picking_type_id': bom_id.picking_type_id or self._get_default_picking_type_id(self.env.company.id), + 'picking_type_id': self.picking_type_id.id, 'product_qty': sum(production.product_uom_qty for production in self), 'product_uom_id': product_id.uom_id.id, 'user_id': user_id.id, diff --git a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py index 4b1cd44929b..6e760a60435 100644 --- a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py +++ b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py @@ -613,3 +613,43 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): self.assertEqual(mo.mrp_production_child_count, 0, "Children MOs counted as existing where there should be none") self.assertEqual(mo.mrp_production_source_count, 0, "Source MOs counted as existing where there should be none") self.assertEqual(mo.mrp_production_backorder_count, 2) + + def test_source_location_on_merge_mo_3_steps(self): + """Check that default values are correct after merging mos when 3-step manufacturing""" + + with Form(self.warehouse) as warehouse: + warehouse.manufacture_steps = 'pbm_sam' + + # picking with non default location + picking_type = self.env['stock.picking.type'].create({ + 'name': 'Manufacturing', + 'code': 'mrp_operation', + 'warehouse_id': warehouse.id, + 'default_location_src_id': self.warehouse.pbm_loc_id.copy().id, + 'default_location_dest_id': self.warehouse.sam_loc_id.copy().id, + 'sequence_code': 'TMP', + 'sequence_id': self.env['ir.sequence'].create({ + 'code': 'mrp.production', + 'name': 'tmp_production_sequence', + }).id, + }) + + mo1_form = Form(self.env['mrp.production']) + mo1_form.product_id = self.finished_product + mo1_form.picking_type_id = picking_type + mo1 = mo1_form.save() + mo1.action_confirm() + + mo2_form = Form(self.env['mrp.production']) + mo2_form.product_id = self.finished_product + mo2_form.picking_type_id = picking_type + mo2 = mo2_form.save() + mo2.action_confirm() + + action = (mo1 + mo2).action_merge() + mo = self.env[action['res_model']].browse(action['res_id']) + + self.assertEqual(picking_type.default_location_src_id, mo.move_raw_ids.location_id, + "The default source location of the merged mo should be the same as the 1st of the original MOs") + self.assertEqual(picking_type, mo.picking_type_id, + "The operation type of the merged mo should be the same as the 1st of the original MOs") diff --git a/addons/mrp/wizard/mrp_production_split.py b/addons/mrp/wizard/mrp_production_split.py index 2752cff97d8..a7c700d5e79 100644 --- a/addons/mrp/wizard/mrp_production_split.py +++ b/addons/mrp/wizard/mrp_production_split.py @@ -98,6 +98,6 @@ class MrpProductionSplitLine(models.TransientModel): 'mrp.production.split', 'Split Production', required=True, ondelete="cascade") quantity = fields.Float('Quantity To Produce', digits='Product Unit of Measure', required=True) user_id = fields.Many2one( - 'res.users', 'Responsible', required=True, + 'res.users', 'Responsible', domain=lambda self: [('groups_id', 'in', self.env.ref('mrp.group_mrp_user').id)]) date = fields.Datetime('Schedule Date')