Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
16894 Vizualizări

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


Imagine profil
Abandonează
Cel mai bun răspuns

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,

Imagine profil
Abandonează
Cel mai bun răspuns

I think that should do

Imagine profil
Abandonează
Autor Cel mai bun răspuns

To jignesh the model should be updated automatically

Imagine profil
Abandonează

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

Autor

Jignesh I need to update the value on the fly

In which model, you have to update name field ?

Autor

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