Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7491 Lượt xem

Hi,

I have a readonly many2one field of hr.employee, I have to do that when I load the form containing this field the employee corresponding to the current logged in user should be filled in the above field. I have tried with onchange method but it doesn’t work for me.​

employee_id = fields.Many2one('hr.employee', string="Employee",readonly=True, required=True)

Thanks in Advance

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

It is better to use default than the onchange method.Try the code below

def _get_employee_id(self):
employee_rec = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)
return employee_rec.id
employee = fields.Many2one('hr.employee', string="Employee", default=_get_employee_id, readonly=True, required=True)


Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 23
1438
1
thg 3 21
5250
2
thg 3 15
6773
4
thg 3 15
12051
1
thg 11 23
5858