Odoo : permission to display the records based on group

Jeevachaithanyan Sivanandan - Apr 4 - - Dev Community

Hi,

in odoo if you need to display records based on permission groups, you can try below snippet. For example

_ Add filter conditions to list the BoMs records based on the conditions where field is_bulk_bom set True or False_

 <record id="group_mrp_bulk_bom" model="res.groups">
            <field name="name">Bulk BoM</field>
            <field name="category_id" ref="base.module_category_manufacturing_manufacturing"/>
        </record>

        <!-- this record rule will show only records with is_bulk_bom is false to user without bulk bom permission -->
        <record id="bulk_bom_records_own" model="ir.rule">
            <field name="name">BOM : is bulk bom False</field>
            <field name="model_id" ref="mrp.model_mrp_bom"/>
            <field name="domain_force">[('is_bulk_bom', '=', False)]</field>
            <field name="groups" eval="[(4, ref('base.group_user'))]"/>
            <field name="perm_read" eval="1"/>
            <field name="perm_write" eval="1"/>
            <field name="perm_create" eval="1"/>
            <field name="perm_unlink" eval="1"/>

        </record>

        <!-- this record rule will show only records with is_bulk_bom is true to user with bulk bom permission -->
        <record id="bulk_bom_records_is_bulk" model="ir.rule">
            <field name="name">BOM : is bulk bom True</field>
            <field name="model_id" ref="mrp.model_mrp_bom"/>
            <field name="domain_force">[('is_bulk_bom', '=', True)]</field>
            <field name="groups" eval="[(4, ref('linco_care.group_mrp_bulk_bom'))]"/>
            <field name="perm_read" eval="1"/>
            <field name="perm_write" eval="1"/>
            <field name="perm_create" eval="1"/>
            <field name="perm_unlink" eval="1"/>
        </record>
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player