Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
6705 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

Thanks @ Mitul +1

Jawaban Terbai

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
Buang
Penulis

Thanks @ Mihran +1

Post Terkait Replies Tampilan Aktivitas
4
Jun 25
12113
2
Agu 22
8176
1
Okt 23
97
4
Apr 23
10984
2
Sep 21
2982