跳至内容
菜单
此问题已终结
1 回复
4205 查看

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]

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
12月 22
21580
5
10月 23
7519
2
4月 19
2770
3
4月 19
3659
2
2月 20
3937