Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
10240 Widoki

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.
Awatar
Odrzuć
Najlepsza odpowiedź

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.


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sie 25
2751
3
lut 25
3959
0
maj 24
46
1
kwi 24
3596
4
wrz 23
5149