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

We are creating a custom module that will help new employees through their first days on the job. We have our own models based on 'hr.employee' and 'hr.plan' (among others). 

When we try and launch a plan for a new employee, the user_id field has to be filled in. This means that there are some extra steps needed in the UI to create a record of the res.user model. To reduce the number of steps needed before launching a plan, we would like to automate this and have the user_id field be filled in automatically.


Does anyone know how this can be done in code instead of using the UI?

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

Hi,

You can use the following code for creating a related user for the employee during his plan launching.

class HrPlanWizard(models.TransientModel):
_inherit = 'hr.plan.wizard'

def action_launch(self):
user_id = self.env["res.users"].create(
{"login": self.employee_id.work_email, "name": self.employee_id.name}
)
self.employee_id.update({'user_id': user_id.id})
return super(HrPlanWizard, self).action_launch()

In the above code, we are creating user with its require fields login and name, you can update the fields which you require in that dictionary.

Hope it helps

Ảnh đại diện
Huỷ bỏ

I tried to make a new user but this is given to me when trying to create a user from custom module
"('You cannot create a new user from here.\n To create new user please go to configuration panel.', 72, 'Go to the configuration panel', None)"
any idea on how to skip this warning?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 21
5101
4
thg 3 15
11900
2
thg 3 15
6649
1
thg 3 24
6875
1
thg 11 19
7338