How to pass value from employee to contact on odoo 16 using code
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 7 25
|
915 | ||
|
1
thg 4 25
|
923 | ||
|
0
thg 3 25
|
891 | ||
|
1
thg 9 24
|
1975 | ||
|
0
thg 8 24
|
1290 |