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

class ArticleArticle(models.Model):

    _name = 'article.article'

     

    name = fields.Char(string='Lib :', required=True)

    price_unit = fields.Float(string='Prix :')

    q_int_en_stock = fields.Integer(string='Stock initiale :')

    img_article = fields.Binary("Image", attachment=True )


class IndexxLineline(models.Model):



 _name = 'indexx.lineline'

 

 

 name = fields.Char(string='Reference', index=True)

 releve_id = fields.Many2one('indexx.indexx', string='Releve')

 article_id = fields.Many2one('article.article', string='Article')

 p = fields.Float(string='Unit Price', readonly=True)

 index_ancien = fields.Float(string='Ancien Index')

 index_nouvel = fields.Float(string='Nouvel Index')

 price_subtotal = fields.Float(compute='_get_lecalcul')


when i select an Article  i need to get his price_unit and put it in the field p, how can i write the onchange function ?!

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

Hi,

Either you can onchange here or you can use the concept of the related field.


Thanks

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

Hi,

Try above: 

@api.onchange('article_id')
 def set_val(self):
    if article_id:
        self.p = self.article_id.price_unit 
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 4 19
3684
1
thg 3 19
4816
0
thg 4 24
955
2
thg 12 22
21601
2
thg 2 20
3953