Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
6 Ответы
38887 Представления

Hai to all,

 I will create a group 'Commission' through xml. then there is any way to add users to this group through the cod(python code) or csv file. this is xml file for creating group

<record model="ir.module.category" id="module_category_commission">
            <field name="name">Commission</field>
            <field name="description">Salesmen Commission Table</field>
            <field name="sequence">20</field>
        </record>

        <record id="salesmen_commission_group" model="res.groups">
            <field name="name">Commission</field>
            <field name="comment">Salesmen Commission Permission Group.</field>
            <field name="category_id" ref="module_category_commission"/>
        </record>

Аватар
Отменить
Лучший ответ

You can set users using this python code. put that in any method and use that method. (Odoo 8)

res_groups = self.pool['res.groups']

users = self.pool['res.users'].search(cr, uid, [], context) #if you not want to set group to all user then set proper domain instead of []

group_id = self.pool['ir.model.data'].get_object(cr, uid, 'your_module_name',  'salesmen_commission_group')

res_groups.write(cr, uid, [group_id], {'users': [(4, user) for user in users]}, context=context)

Odoo13:
users = self.env['res.users'].search([]) #if you not want to set group to all user then set proper domain instead of []

group_id = self.env.ref('your_module_name.group_name')
group_id.users = [(4, user.id) for user in users]

Аватар
Отменить

Thanks, It's working for me +1

Лучший ответ

Here is example of adding the admin user to the group you have created trough the XML:

        <record model="res.groups" id="salesmen_commission_group">
            <field name="name">Commission</field>
            <field name="comment">Salesmen Commission Permission Group.</field>
            <field name="category_id" ref="module_category_commission"/>
            <field name="users" eval="[(4, ref('base.user_root'))]"/>
        </record>

 

Аватар
Отменить
Лучший ответ

Hi dude,

You can try with this for python

def set_commission_group(self, user_id):
commission_group = self.env.ref('your_module_name.salesmen_commission_group')
commission_group.write({'users': [(4, user_id)]})
Аватар
Отменить
Лучший ответ

Hi, Carefull with this action you will reset the group members with users items

instead we can can just add on remove a user with + and -
usersToAdd = searching user with domain or somthing
group = env['res.groups'].search([('id', '=', GROUP_ID)])
group.write({'users' : group.users + usersToAdd})
or
group.write({'users' : group.users - usersToAdd})

Аватар
Отменить
Лучший ответ

If you were trying to add user into an existing group with noupdate on, this might be the best and only way for you to add user into the group


<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="base.user_admin" model="res.users">
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]"/>
</record>
</data>
</odoo>
Аватар
Отменить
Лучший ответ

Hi,

in my case it worked in the following way


@api.multi
def assign_perms(self):
    users_id = [1, 2, 3, 4, 5, .........]
    aux_users = [(4, i) for i in users_id]
    group = self.env['res.groups'].search([('id', '=', self.env.ref('module_name.identifier').id)])
    group.write({'users': aux_users})

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
апр. 25
3596
3
дек. 22
11485
5
апр. 24
42007
3
мар. 24
10497
2
июл. 19
765