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
- Бухоблік
- Склад
- PoS
- Project
- MRP
Це запитання позначене
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
РеєстраціяRelated Posts | Відповіді | Переглядів | Дія | |
---|---|---|---|---|
|
1
лип. 25
|
787 | ||
|
1
квіт. 25
|
845 | ||
|
0
бер. 25
|
799 | ||
|
1
вер. 24
|
1878 | ||
|
0
серп. 24
|
1216 |