Odoo 16 is an open-source ERP system that provides a wide range of functionalities to manage various business operations. Record rules are an important security feature in Odoo that allow you to control access to records in the system. Record rules can be created for any model in Odoo and are used to define the domain expression that filters the records that a user can access.
The Odoo 16 Record Rule can be created using the following steps
Step 1: Go to the Settings menu and select “Technical -> Security -> Record Rules.”
2. Click on the “Create” button to create a record rule.
Step 3: In the “Name” field, enter a descriptive name for the record rule.
Step 4: In the “Object” field, select the model for which you want to create the record rule.
For example, if you want to create a rule for restricting access to sales orders, select the “Sales Orders” model.
We will examine the XML code for creating a record rule in Odoo 16. Here’s an example:
<record id="demo_record_user_rule" model="ir.rule"> <field name="name">User can only see their own records</field> <field ref="module.model_name" name="model_id"/> <field name="domain_force">[('team_id', '=', user.sale_team_id.id)]</field> <field name="groups" eval="[(4, ref('base.group_user'))]"/> <field name="perm_read" eval="True"/> <field name="perm_write" eval="False"/> <field name="perm_create" eval="False"/> <field name="perm_unlink" eval="False"/> <field name="active" eval="False"/> </record>
Step 5: In the “Domain” field, enter the domain expression that defines the conditions under
Which the rule applies. For example, if you want to create a rule that restricts access to sales orders to the sales team, you can use the domain expression: [(‘team_id’, ‘=’, user.sale_team_id.id)]. The domain expression can be complex and can use various operators such as ‘=’, ‘! =’, ‘<‘, ‘>’, etc.
Step 6: In the “Groups” field, select the groups that will have access to the records that match the domain expression. You can select multiple groups by holding down the Ctrl key while clicking on the groups.
Step 7: Save the record rule by clicking on the “Save” button.
Once the record rule is saved, the selected groups will only have access to the records that match the domain expression. I will hide any records that do not match the domain expression from the selected groups. You can create multiple record rules for the same model, and the rules will be combined using the OR operator.
In conclusion, creating a record rule in Odoo 16 is a simple process that allows you to control access to records in the system. By defining a domain expression and selecting the groups, you can also ensure that the right users have access to the right records. Record rules are an important security feature in Odoo. And they can also help you protect your data and ensure that your business processes are followed correctly.