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


I create group called 'Skill Creater'

I am not need to assign group for employee like

goto>>settings>>users>>tik 'Skill creater'


In my py code:-

skill_creater = fields.Many2many('res.users')

In xml code

<fields name="skill_creater" widget="many2many_tags/>


My question is,

 if i select 2 users , these 2 users are assigned to 'Skill Creater' group via python code .

Is it Possible?

Is possible then how to do this?

And How to i identify these employees are now under "Skill Creator "Group?


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

Hi Ajini,

You can first search the security groups in the Python code and then you can add users to it with a write operation. For example:

your_group = self.env.ref('your_module.skill_creator')
# Your filter criteria here: ​
users = self.env['res.users'].search([('name', '=', 'SomeCondition')])
for user in users:
    your_group.write({
        'users': [(4, user.id)]
    })  
Alternatively you can also remove a user from a group like this:
for user in users:
    your_group.write({
        'users': [(3, user.id)]
    })  

And finally to check if a user belongs to a group:

for user in users:
    if user.has_group('your_module.skill_creator'):
        # Your custom logic here - this user is within the group!
    if not user.has_group('your_module.skill_creator'):
        # Your custom logic here - this user is NOT within the group! 
              

Regards,

Yenthe

Ảnh đại diện
Huỷ bỏ
Tác giả

thank you, its work

Câu trả lời hay nhất

Hello,

you can try to use res.user object write method and add group id using [4,id] into user write method. it will help you..

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