Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
5822 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć

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?

Powiązane posty Odpowiedzi Widoki Czynność
1
mar 21
5212
4
mar 15
12027
2
mar 15
6752
1
mar 24
6985
1
lis 19
7458