Create Record Rules in Odoo 17

TEENA
December 21, 2023
create-record-rules-in-odoo15

The robust security framework of Odoo, an advanced open-source ERP and business management system, enables administrators to manage record access through record rules. Record rules specify the requirements that must be fulfilled by a user to read, edit, add, or remove records within a particular model.

This blog post will guide you through Odoo 17’s record rule-setting process.

The four access modes for record rules are CREATE, READ, WRITE, and DELETE. Users can also use CREATE to create new records, READ to view records, WRITE to edit records, and DELETE to delete records. By incorporating these access modes into our record rules, we can precisely limit the actions that users can take with the records in our model.

Now let’s examine the exact XML code that was used to create a record rule in Odoo 17.

<record id="demo_record_user_rule" model="ir.rule">

          <field name="name"> see only own records</field>

          <field name="model_id" ref="model_id"/>

          <field name="domain_force">[('user_id', '=', self.uid)]</field>

          <field name="groups" eval="[(4, ref('base.group_user'))]"/>

          <field name="perm_create" eval="0"/>

          <field name="perm_write" eval="0"/>

          <field name="perm_unlink" eval="0"/>

          <field name="perm_read" eval="1"/

</record>

Now we create a rule called “demo_record_user_rule”. This rule is easy to understand by looking at the domain name. The data type of this policy is specified by the ‘model_id’ field.

We specify the criteria for the decision in the “domain_force” field. In this example, the ‘user_id’ field is used to restrict access to data based on the active user ID. When the name is set to “[(‘user_id’, ‘=’, self. uid)]”, users can only view records whose “user_id” field matches their unique ID.

The user groups that are authorized to use this record rule are listed in the “groups” field. In this instance, users who are a part of the “base.group_user” group are being granted access.

We identify the kinds of operations that users can carry out with this record rule for the “perm_read,” “perm_write,” “perm_create,” and “perm_unlink” fields. In this case, users are not allowed to create, edit, or remove records; they are only allowed to read them.

We store our record rule in the security folder of our Odoo module after we’ve configured it using XML. By doing this, the record rule in Odoo 17 becomes visible in the Record Rules menu located under the Security section.

The rule we created is located in the security settings’ Record Rules menu.

From here, we can choose to immediately create a record rule.

create-record-rule

Test your record rule under the given conditions to ensure that it is effective. Make sure the rule complies with your needs regarding data access control. You can also optimize security, simplify business procedures, and fine-tune data access with Odoo 17 by putting record rules into place. You can also take control of your data and make sure that users interact with information in a way that complies with your organization’s policies by making use of this feature.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *