Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
1308 มุมมอง

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)


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 22
3863
3
เม.ย. 20
10273
1
พ.ค. 21
9424
0
ธ.ค. 20
4797
2
ก.ค. 20
3313