تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
6 الردود
38565 أدوات العرض

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
أبريل 25
3437
3
ديسمبر 22
11243
5
أبريل 24
41720
3
مارس 24
10318
2
يوليو 19
765