From 8e4e32ab01b8c7be8d76bd857ff7c4a5274fcea4 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Wed, 21 Dec 2022 11:30:08 +0000 Subject: [PATCH] [FIX] mrp: use the operation type set on the BoM in MO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Enable “Multi-Step Routes” option in the inventory settings - Create a storable product “P1” with BoM: - Add any Component - Go to “Miscellaneous” tab - Create a new picking type and set in the “Operation” tab - Create a Mo: - Add the product “P1” - Select the created BoM - Go to “Miscellaneous” tab Problem: The operation type set on BoM does not update when selecting the BoM on a manufacturing order opw-3091436 closes odoo/odoo#108632 X-original-commit: cd561574d044d4799163ac90305c7914855ead50 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/mrp/models/mrp_production.py | 5 ++++- addons/mrp/tests/test_order.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 93ff38c54dc..61f08262775 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -266,7 +266,7 @@ class MrpProduction(models.Model): for production in self: production.mrp_production_backorder_count = len(production.procurement_group_id.mrp_production_ids) - @api.depends('company_id') + @api.depends('company_id', 'bom_id') def _compute_picking_type_id(self): domain = [ ('code', '=', 'mrp_operation'), @@ -275,6 +275,9 @@ class MrpProduction(models.Model): picking_types = self.env['stock.picking.type'].search_read(domain, ['company_id'], load=False, limit=1) picking_type_by_company = {pt['company_id']: pt['id'] for pt in picking_types} for mo in self: + if mo.bom_id and mo.bom_id.picking_type_id: + mo.picking_type_id = mo.bom_id.picking_type_id + continue if mo.picking_type_id and mo.picking_type_id.company_id == mo.company_id: continue mo.picking_type_id = picking_type_by_company.get(mo.company_id.id, False) diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 7c47ea27f88..a0e6c6ed150 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -3185,3 +3185,32 @@ class TestMrpOrder(TestMrpCommon): raw.product_uom_qty = 1.25 self.assertEqual(mo.move_raw_ids.quantity_done, 1.25) + + def test_compute_picking_type_id(self): + """ + Test that the operation type set on the bom is set in the manufacturing order + when selecting the BoM""" + self.env.user.groups_id += self.env.ref("stock.group_adv_location") + picking_type = self.env['stock.picking.type'].create({ + 'name': 'new_picking_type', + 'code': 'internal', + 'sequence_code': 'NPT', + 'default_location_src_id': self.env.ref('stock.stock_location_stock').id, + 'default_location_dest_id': self.stock_location_components.id, + 'warehouse_id': self.warehouse_1.id, + }) + self.bom_1.picking_type_id = picking_type + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = self.bom_1 + mo = mo_form.save() + self.assertEqual(mo.picking_type_id.id, picking_type.id) + # MO_2 + self.assertFalse(self.bom_2.picking_type_id) + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = self.bom_2 + mo_2 = mo_form.save() + picking_type_company = self.env['stock.picking.type'].search_read([ + ('code', '=', 'mrp_operation'), + ('warehouse_id.company_id', 'in', mo_2.company_id.ids), + ], ['company_id'], load=False, limit=1) + self.assertEqual(mo_2.picking_type_id.id, picking_type_company[0]['id'])