This question has been flagged
3 Replies
15102 Views

I have two models 


class TestA(models.Model):

 _name = 'test.A'

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

 amount = fields.Float(string='Amount', required=True)


 class TestB(models.Model):

 _name = 'test.b'

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


I want to update the name field in test.b model with the value in name field in test.a


Thanks in advance


Avatar
Discard
Best Answer

Hello Vineeth,

Add 1 more many2one field of model 'test.A' into the model 'test.B' and then you can make related field of name field in model 'test.B'

For Ex:-

class TestA(models.Model):
    _name = 'test.A'

     name = fields.Char(string='Material', required=True)
     amount = fields.Float(string='Amount', required=True)


class TestB(models.Model):
    _name = 'test.b'

    a_id = fields.Many2one('test.A', 'A id')
    name = fields.Char(string='Material', related='a_id.name')

Now You can create 1 record in 'test.A' model. And when you create new record in 'test.B' model, select a_id and then name is automatically updated with 'test.A' name.

Hope it will helps you.
Thanks,

Avatar
Discard
Best Answer

I think that should do

Avatar
Discard
Author Best Answer

To jignesh the model should be updated automatically

Avatar
Discard

test.B name field updated automatically while you select value for a_id in test.B field

Author

Jignesh I need to update the value on the fly

In which model, you have to update name field ?

Author

test.b

Name field in 'test.B' object is related, so it change on the fly when you select a_id in model 'test.B'.

Another solution is, used onchange function of a_id in model 'test.B'

Like,

@api.onchange('a_id')

def a_id_onchange(self):

if self.a_id:

self.name = self.a_id.name