Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2797 มุมมอง

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 ?!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

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


Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Try above: 

@api.onchange('article_id')
 def set_val(self):
    if article_id:
        self.p = self.article_id.price_unit 
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
เม.ย. 19
3686
1
มี.ค. 19
4817
0
เม.ย. 24
961
2
ธ.ค. 22
21609
2
ก.พ. 20
3959