Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
6728 Vues

Hello All,

I have 100+ users, some users have different-different groups

How can I achive this using python script or  what's the standard way to import it. ?

Thanks in Advance.



Avatar
Ignorer
Meilleure réponse

Hello Ankit,

based on the amount of data it depends.  if you have some validation on import like duplicate data will be skip and etc.. at that time you can use python script. 

1. using python script also you can import.

for eg.    self.env['res.users'].create({'name': 'abc', 'login': 'abc@mail.com', 'groups_id': [(6, 0, [list of groups ids])]})

2. using odoo's import feature you can import the .csv file and assign different groups to user as per below screen you can see.

https://prnt.sc/oaeae0

Avatar
Ignorer
Auteur

Thanks @ Mitul +1

Meilleure réponse

Hi Ankit,


You can import the user details using a csv file or an excel file. When I tried importing users the last day, it was taking an unusual amount of time. So I wrote a simple python function to create users and assign correct permissions. To set the correct permissions, find the field names of the permissions you need to apply while creating the users. These field name will be like 'sel_groups_1_9_10'. Just as the name suggests, those numbers are the values which the field can take. So create a list of dictionaries, with the users and their details. For example

users = [('name': 'Test', 'login': 'test@test.com', 'email': 'test@test.com', 'password': '', 'sel_groups_1_9_10': 1), ('name': 'Employee', 'login': 'employee')]

Now iterate over this list of dictionaries and create users based on these values.


for each in list:
    self.env['res.users'].create({'name': each['name'], 'login': each['email'], 'password': '',
'sel_groups_11_12': each['sel_groups_11_12'], 'sel_groups_17_18': each['sel_groups_17_18']})

This will create users with the corresponding values given in the list
Avatar
Ignorer
Auteur

Thanks @ Mihran +1

Publications associées Réponses Vues Activité
4
juin 25
12139
2
août 22
8190
1
oct. 23
97
4
avr. 23
11020
2
sept. 21
2988