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

when I create a new company, the company_registry value in res.partner (Customers - Sales) is not filled in automatically. I want it to be filled in automatically if res.company already has a company_registry value. Please correct the model if there is something wrong...



from odoo import models, fields
class ResPartner(models.Model):    _inherit = 'res.partner'
    company_registry = fields.Char(string='Company Registry')        def create(self, vals):        company_id = vals.get('company_id')        if company_id:            company = self.env['res.company'].browse(company_id)            if company.company_registry:                vals['company_registry'] = company.company_registry        return super(ResPartner, self).create(vals)
    def write(self, vals):        if 'company_id' in vals:            company = self.env['res.company'].browse(vals['company_id'])            if company.company_registry:                vals['company_registry'] = company.company_registry        return super(ResPartner, self).write(vals)
Avatar
Annuleer
Beste antwoord

Hellow,
Why not you simplify it by removing the function create​ and write​, and then change the property for the field declaration like this:

company_registry = fields.Char(
​store=True,
​​string='Company Registry',
​related='company_id.company_registry')
Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
sep. 24
1176
1
okt. 24
1469
1
mei 24
1002
2
aug. 25
270
2
aug. 25
191