Skip to Content
Menu
This question has been flagged
2 Replies
1448 Views

I want to take the values that have been filled in in res.company and display them in res.partner (Customes - Sales). so I added a new field. and want to display the company_registry according to the one in res.company. but I'm always wrong. Please help me...


from odoo import models, fields, api
class ResPartner(models.Model):    _inherit = 'res.partner'
    company_registry = fields.Char(string='Company Registry', compute='_compute_company_registry', store=True)
    @api.depends('company_id')    def _compute_company_registry(self):        for partner in self:            # Get the company_registry from the related company            partner.company_registry = partner.company_id.company_registry if partner.company_id else False
    @api.onchange('company_id')    def _onchange_company_id(self):        for partner in self:            if partner.is_company and partner.company_id:                partner.company_registry = partner.company_id.company_registry            else:                partner.company_registry = False
    @api.model    def create(self, vals):        # If a company is set, get its company_registry        if vals.get('is_company') and vals.get('company_id'):            company = self.env['res.company'].browse(vals['company_id'])            vals['company_registry'] = company.company_registry if company else False
        return super(ResPartner, self).create(vals)
    def write(self, vals):        # If the company_id is changed, update the company_registry        if 'company_id' in vals:            company = self.env['res.company'].browse(vals['company_id'])            if company:                vals['company_registry'] = company.company_registry            else:                vals['company_registry'] = False
        return super(ResPartner, self).write(vals)


Avatar
Discard
Author Best Answer

the code runs. but the flow is if you make a quotation in Sales with a customer according to the one in the company, then the sequence format is 'company_registry-sequence'. When I save the quotation, the company_registry doesn't appear instead it has ''00-00001'. In Companies, I have filled in the company_registry.

Avatar
Discard
Best Answer

Hi,
The code seems to be fine, what it does is, if you add a contact/customer and set the company for the contact, the company_registry field will be filled by the company_registry inside the company

Is it not working like this ?

Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 22
3997
3
Apr 20
10446
1
May 21
9608
0
Dec 20
4954
2
Jul 20
3409