Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
10242 Переглядів

Hello,

I want to display value to  another model field with create function.

Any help please?

class MyClass1(models.Model):
    _inherit = 'x.x'
    field1 = fields.Char(string='A')
   
    @api.model
    def create(self, vals):
       #field1
        result = super(MyClass1, self).create(vals)
        return result


class MyClass2(models.Model):
    _inherit = 'z.z'
    field2 = fields.Char(string='B')
   

    @api.model
    def create(self, vals):
        # field2 = field1
        result = super(MyClass2, self).create(vals)
        return result

Thanks.
Аватар
Відмінити
Найкраща відповідь

Based on what condition you want to search the record from "x.x" object? There should be some condition to fetch the single record out of hundreds or thousands of records.

class MyClass2(models.Model):
    _inherit = 'z.z'

@api.model
def create(self, vals):
field1 = self.env['x.x'].search([('field1', '=', 'Some Value')], limit=1).field1
vals.update({'field2': field1})
return super(MyClass2, self).create(vals)

In the example, [('field1', '=', 'Some Value')] is a condition (domain) to search the record from another object.


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
серп. 25
2753
3
лют. 25
3964
0
трав. 24
46
1
квіт. 24
3596
4
вер. 23
5150