Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
10239 Weergaven

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.
Avatar
Annuleer
Beste antwoord

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.


Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
aug. 25
2751
3
feb. 25
3959
0
mei 24
46
1
apr. 24
3596
4
sep. 23
5149