跳至內容
選單
此問題已被標幟
1 回覆
5732 瀏覽次數

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?

頭像
捨棄
最佳答案

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

頭像
捨棄

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?

相關帖文 回覆 瀏覽次數 活動
1
3月 21
5142
4
3月 15
11946
2
3月 15
6683
1
3月 24
6914
1
11月 19
7388