This question has been flagged
1 Reply
3492 Views

Hello all,

v:10.0

I am trying to create a 'product.product' record from a 'mrp.bom' record and have it create a 'mrp.bom.line' on that bom :

class MrpBom(models.Model):    

_inherit = 'mrp.bom'

bom_custom_ids = fields.One2many(comodel_name='product.product', ondelete='cascade', copy='True', inverse_name='master_bom', string='Sous-ensembles')


class ProductProduct(models.Model):    

_inherit = "product.product"

def create(self,vals):        

res = super(ProductProduct,self).create(vals) 

bom = vals.get('master_bom')        

if bom:            

vals={                

'bom_id': bom,                

'product_id':self.id,                

'product_qty':1,           

 }            

bom_lines = self.env['mrp.bom.line'].create(vals)        

return res        

master_bom = fields.Many2one(comodel_name="mrp.bom", inverse_name='bom_custom_ids', string='Master bom')


I get a bad query return saying the product_id isn't supplied for the create() method on 'mrp.bom.line'...

I am guessing at the time of runing the 'product.product' record isn't yet validated in the DB.

Is there a way around this behaviour ?

Regards


Avatar
Discard
Best Answer

vals= {                
   'bom_id': bom,               
   'product_id': res.id,                
   'product_qty': 1, 
}            

Avatar
Discard