DEV Community

Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

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

Top comments (0)