Help

0

how to implement the onchage method to get the bom_id when i select a product_id ?

Avatar
Heithem Galmami

i got this class

 class estimation_cout(models.Model):

 _name = "estimation.cout"

 product_id = fields.Many2one('product.product', string='Produit')

 bom_id = fields.Many2one('mrp.bom', string='Nomenclature')

 when i select a product i want to get his bom like in MRP can u please tell me what and how i should write the onchage to make that works

1 Comment
Avatar
Discard
Avatar
Sehrish
-

Onchange many2one filed in odoo: https://goo.gl/CBP9og

1 Answer
0
Avatar
Niyas Raphy
Best Answer

Hi,

See this onchange for the product_id field in the function in Manufacturing Order model.


@api.onchange('product_id', 'picking_type_id', 'company_id')
def onchange_product_id(self):
""" Finds UoM of changed product. """
if not self.product_id:
self.bom_id = False
else:
bom = self.env['mrp.bom']._bom_find(product=self.product_id, picking_type=self.picking_type_id, company_id=self.company_id.id)
if bom.type == 'normal':
self.bom_id = bom.id
self.product_qty = self.bom_id.product_qty
self.product_uom_id = self.bom_id.product_uom_id.id
else:
self.bom_id = False
self.product_uom_id = self.product_id.uom_id.id
return {'domain': {'product_uom_id': [('category_id', '=', self.product_id.uom_id.category_id.id)]}}


You can change little changes here and use the same in your case.

Thanks

Avatar
Discard