跳至內容
選單
此問題已被標幟
2 回覆
8541 瀏覽次數

class test1(models.Model):
    """docstring for ClassName"""
    _name = 'test.test1'
    _rec_name = 'name'

    id = fields.Char(string='ID Test 1', required=True)
    name = fields.Char(string='Name ID Test 1', required=True)
    price = fields.Float(string='Price ID Test 1', required=True)


class test2(models.Model):
    _name = 'test.test2'

    test1_name = fields.Many2one("test.test1", "List test 1", required=True)
    amount = fields.Integer(string='Amount', required=True, default='1')
    mymoney = fields.Float(string="Money", readonly=True)# mymoney = amount * price

    @api.onchange("test1_name")
    def onchange_test2(self):
        #self.mymoney = ?????  <============

How to get data "price" from test1 classes for caculate?

Thanks

頭像
捨棄
最佳答案

You have Many2one field of test.test1, you can use that field and get price of that 'test.test1' class record.

You can access like this:

self.test1_name.price

your code will be like following: 

    @api.onchange("test1_name")    

    def onchange_test2(self):    

        self.mymoney = self.test1_name.price


頭像
捨棄
最佳答案

Hi van, 

if self.test1_name:
result = self.amount * self.test1_name.price
self.mymoney = result
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
2月 25
5899
1
12月 24
1450
1
11月 22
15963
3
8月 22
12989
2
8月 22
4476