how-to-create-security-group-odoo-13.png
Blogger_637068746542562782.png
By: Abdul Afras

How to Create a Security Group in Odoo 13

Technical Odoo 13 Sales

In any business management, we have many users who have different responsibilities and rights. So not all the functionalities should be displayed to all the users. In the case of Odoo Sale Management, the administrator can see all the sales but a salesman can see only his sales. This is done by using security groups. The administrator has a security group as well as a salesman. We can define record rules based on the security groups. Also in Odoo, we can specify the groups to menu or fields for which the menu or field will be displayed for that particular security group. 

In this blog, I will create the security groups for my custom module overtime

Firstly I will create two security groups, one is for the manager and another one is for the user. 

The Manager will have full rights but the user will have only limited rights.

Make an XML file under the security directory to add the security groups. 

         <record model="ir.module.category" id="module_management">
             <field name="name">Overtime</field>
             <field name="description">User access level for Overtime module</field>
             <field name="sequence">20</field>
        </record>

This will create an option in the user’s form with the name Overtime. We need to add the security group so that the user can select the access rights.

         <record id="overtime_user" model="res.groups">
            <field name="name">User</field>
            <field name="category_id" ref="module_management"/>
        </record>
        <record id="overtime_manager" model="res.groups">
            <field name="name">Manager</field>
            <field name="category_id" ref="module_management"/>
            <field name="implied_ids" eval="[(4, ref('overtime_user'))]"/>
        </record>

This code will create a security group for both the user and the manager

When creating the user’s group we are only mentioning the name of the security group and the category_id to which they belong. We have already created the category above so we need to give the id of the category. When it comes to the manager we are giving the name and the category id like the user but we also gave the implied_ids, that is because you can see in implied ids we are given the id of the user security group which means the manager will have the rights that are given to the user. 

So if you goto general settings, on debug mode under the Users & Companies menu item you can see a menu item called Groups
       how-to-create-security-group-odoo-13-cybrosys

Under the groups, we can see all the security groups that are been created. We can also see the security group that we created just now.

how-to-create-security-group-odoo-13-cybrosys

Also in the user’s settings, we can see the two groups will be displayed under the category Overtime and we can choose the security group for the users.

how-to-create-security-group-odoo-13-cybrosys

We can also add the groups to the Menu item. Sometimes we don’t want to see some of the menu items for the users. We can specify the group for which we want to display the menu item by adding groups to the Menu item. 

        <menuitem name="Overtime"
                  id="overtime.menu_1"
                  parent="overtime.menu_root"
                  action="action_window"
                  groups="overtime_manager"/>

So the users with the security group overtime_manager will only see the menu item.

Now we have a model and we have a security group. Next thing we have to do is we have to add ir.model.access.csv file under security. 

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_admin,Access Manager,model_overtime_overtime,overtime_user,1,1,1,0
access_user,Acess user,model_overtime_overtime,overtime_manager,1,1,1,1

To know more about security you can see our Blog Security in Odoo.



cybrosys youtube

Comments

0


Leave a comment

 
Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message
 
 
 
 
Close
cybrosys