Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
4744 Переглядів

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


Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
вер. 15
3380
2
лют. 25
975
1
бер. 15
5641
0
бер. 15
3665
1
бер. 15
8029