Dejan Dakovic
Dejan Dakovic

Reputation: 155

how to set the value of the "x" field, depending on the "y" field from another model? Odoo-10

I want to enter the value in field "y" from class "yCla", depending of value from field "x" from class "xCla"

class xCla(models.Model):
    . . .
    x = fields.Char()

class yCla(models.Model):
    #I did not inherit anything
    #this two models are from same module
    . . .
    y = fields.Char()

if I was not clear enough, please tell me

Upvotes: 1

Views: 114

Answers (2)

Dejan Dakovic
Dejan Dakovic

Reputation: 155

Thanks for the advice @arryph , I added this in my code and now I work as I wanted

class xCla(models.Model):
    _name = 'x_name'
    . . .
    x = fields.Char()

class yCla(models.Model):
    _name = 'y_name'
    . . .
    abc = fields.Many2one('x_name')
    y = fields.Char()

    @api.onchange('abc')
    def _onchange_abc_x(self):
        self.y = self.abc.x

If someone knows a easy way, please let write in the answers :)

Upvotes: 0

arryph
arryph

Reputation: 2825

If there is no relation between this two models xCLa and yCla, then the easiest way will be to implement the logic in xCla models write or create function. But if they are related for example there is relation between yCla and xCla, then this can be achieved by using compute or related functionality on field properties.

Upvotes: 1

Related Questions