Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4210 Widoki

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

Awatar
Odrzuć

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]

Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
gru 22
21585
5
paź 23
7522
2
kwi 19
2776
3
kwi 19
3661
2
lut 20
3939