Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4689 Lượt xem

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 15
3340
2
thg 2 25
896
1
thg 3 15
5583
0
thg 3 15
3638
1
thg 3 15
7995