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
Onchange many2one filed in odoo: https://goo.gl/CBP9og
Try like below
@api.onchange("product_id")
def _onchange_product_id(self):
if not self.product_id:
self.quantity = False
self.bom_id = False
self.order_line = False
elif self.product_id:
bom = self.env["mrp.bom"].search([
("product_tmpl_id", "=", self.product_tmpl_id.id)])
if bom:
self.bom_id = bom[0]