跳至內容
選單
此問題已被標幟
6 回覆
38386 瀏覽次數

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})

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
4月 25
3302
3
12月 22
11141
5
4月 24
41515
3
3月 24
10244
2
7月 19
765