Hi, guys. I made a custom form which is have department field that I take from hr.employee but its related with hr.department model.
how can I get the department name field value? please help
Odoo is the world's easiest all-in-one management software.
 It includes hundreds of business apps:
Hi, guys. I made a custom form which is have department field that I take from hr.employee but its related with hr.department model.
how can I get the department name field value? please help
I just solved my problem. Thank you guys for the idea. Here is the code
@api.onchange('name_req')
    def get_department(self):
        for res in self:
            res.department_id = res.name_req.department_id
            dept_temp = res.department_id
            res.dept = dept_temp.name
Hi,
The field 'department_id' is the many2one relational field in the model 'hr.employee' to the 'hr.department' model. To get the name of the department of an employee you can call 'department_id.name' .
Regards.
I did try those code but it gave me value like this "Department = hr.department(9,)"
Hello there are two ways.
1. Using related to field
Like add Many2one field in your form view. This many2one fields related to 
"hr.department"
department_id = fields.many2one(related="employee_field_id.department_id")
2. Using onchange or Compute method 
department_id = fields.many2one("
hr.department")
@api.onchage('employee_id')
def get_employee_dept(self):
for res in self:
if res.employee_id:
res.department_id = res.employee_id.department_id
else:
res.department_id
= False
Thanks
I did try those code but it gave me value like this "Department = hr.department(9,)"
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
Daftar| Post Terkait | Replies | Tampilan | Aktivitas | |
|---|---|---|---|---|
|  | 2 Jul 22  | 5278 | ||
|  | 3 Jul 23  | 6486 | ||
| 
            
                Get all the users that belong to a group Odoo15
            
            
                    Diselesaikan
            
         |  | 2 Mar 24  | 6414 | |
| 
            
                Unable to remove fields created by Studio
            
            
                    Diselesaikan
            
         |  | 1 Nov 22  | 6414 | |
|  | 2 Okt 22  | 4394 | 
You must read these odoo development guide lines: https://sites.google.com/view/thinkincode/erp/odoo