Skip to Content
Menu
This question has been flagged
2 Replies
7884 Views

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

Avatar
Discard
Best Answer

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


Avatar
Discard
Best Answer

Hi van, 

if self.test1_name:
result = self.amount * self.test1_name.price
self.mymoney = result
Avatar
Discard
Related Posts Replies Views Activity
1
Nov 22
14645
3
Aug 22
10750
2
Aug 22
3045
0
Jul 22
835
2
Oct 21
1433