[FIX] mrp: use the operation type set on the BoM in MO

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) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-12-26 11:39:49 +01:00
parent 2a015600b2
commit 8e4e32ab01
2 changed files with 33 additions and 1 deletions
+4 -1
View File
@@ -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)
+29
View File
@@ -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'])