DEV Community

Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

1

Odoo : Add conditions to list view, custom record rules

The below code explains how to add conditions on list views in a model with custom record rules.

for our test case, the model mrp.bom has a field - is_bulk_bom, so we need to display the list of records based this field set and if the user has the group permission group_mrp_bulk_bom


        <!-- 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>
Enter fullscreen mode Exit fullscreen mode

        <!-- 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('module_name.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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

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

👋 Kindness is contagious

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

Okay