DEV Community

Cover image for Odoo : permission to display the records based on group
Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

1

Odoo : permission to display the records based on group

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay