Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Add users to group through python code

By
shameem
on 2/28/15, 2:16 AM 3,158 views

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>

1
Turkesh Patel
On 2/28/15, 5:01 AM

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

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)

0
Jordan Vrtanoski
On 2/28/15, 3:40 AM

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>

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/28/15, 2:16 AM
Seen: 3158 times
Last updated: 3/16/15, 8:10 AM