Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
1279 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
lis 22
3832
3
dub 20
10234
1
kvě 21
9390
0
pro 20
4769
2
čvc 20
3289