Skip to Content
Menu
This question has been flagged
4 Replies
2726 Views

Hi.........

I am doing OT Request for a department .I want to change department_id, job_id and  department_manager like i save in profile when i put a Employee.

That's my field,

name = fields.Many2one('hr.employee',"Name",required=True)

department_id = fields.Many2one('hr.department',"Department")
job_id = fields.Many2one('hr.job',"Job Title",required=True)
department_manager = fields.Many2one('hr.employee',"Department Manager")

Thank you..


Avatar
Discard

Thank to all of you.It is really helpful answers for me..




Onchange many2one filed in odoo: https://goo.gl/CBP9og

Best Answer

Hi Hannay,

You would find lots of examples of the onchange if you just google it.
Try following code:

@api.onchange('name')
def onchange_employee(self):
    self.job_id = self.name.job_id.id
    self.department_id = self.name.department_id.id


Avatar
Discard
Best Answer

Hi Hannay,

For your code follow like below:

@api.onchange('name')
def onchange_employee_details(self):
for file in self:
if file.name:
file.job_id = file.name.job_id.id
file.department_id = file.name.department_id.id



Avatar
Discard
Best Answer

hi,   

You can use the related attribute.
eg:

employee_id = fields.Many2one('hr.employee',"Name",required=True)

department_id = fields.Many2one('hr.department',"Department",related='employee_id.department_id') 

job_id = fields.Many2one('hr.job',"Job Title",required=True,related='employee_id.job_id') 

department_manager = fields.Many2one('hr.employee',"Department Manager",related='employee_id.parent_id') 


Avatar
Discard