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

How to pass value from employee to contact on odoo 16 using code

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

Employee and partner are connected by 'address_id' field in odoo 17.
you can pass values from employee by inheriting 'create' or 'write' method or by calling your custom method.

@api.model
def create(self, vals):
result = super(ClassName, self).create(vals)
result.address_id.write({'field_in_partner': value_from_employee}
return result
def write(self, vals):
res = super(ClassName, self).write(vals)
​ self.address_id.write({'field_in_partner': value_from_employee}
return res
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

from odoo import models


class HrEmployee(models.Model):

    _inherit = 'hr.employee'


    def sync_employee_to_contact(self):

        for employee in self:

            if employee.address_home_id:

                contact = employee.address_home_id

                contact.write({

                    'email': employee.work_email or employee.private_email,

                    'phone': employee.work_phone,

                    'function': employee.job_title,

                })

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

from odoo import models


class HrEmployee(models.Model):

    _inherit = 'hr.employee'


    def get_partner_country(self):

        for employee in self:

            if employee.related_partner_id and employee.related_partner_id.country_id:

                partner_country = employee.related_partner_id.country_id.name

                print('Partner Country:', partner_country)

            else:

                print('No related partner or country assigned.')

Hope it helps you

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

Hi,


In the 'hr.employee' model, a many2one field named 'related_partner_id' connects the 'hr.employee' (Employee) with the 'res.partner' (Contact). This field allows us to access all the fields in the 'res.partner' model.


Eg:

class HrEmployee(models.Model):
_inherit = 'hr.employee'

def get_partner_country(self):
partner_country = self.related_partner_id.country_id
print('Partner Country',partner_country)

Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 25
597
1
เม.ย. 25
676
0
มี.ค. 25
681
1
ก.ย. 24
1712
0
ส.ค. 24
1027