Odoo Custom Module Development Part 3 - Security and Access Rights
This is the third article in the Odoo custom module development series.
In Part 2, we created our models and fields. In this article, we will add security so the models can be used by real users in a controlled way.
Security is not optional in Odoo. A model without proper access rights will either be inaccessible or dangerously open.
What we will add
We will create:
- module category
- user groups
- access rights with
ir.model.access.csv - an example record rule
1. Create a security XML file for groups
Create this file:
estate/security/estate_security.xml |
Add the following content:
<odoo> |
What this does:
- creates a dedicated category on the user form
- creates a normal estate user role
- creates an estate manager role that automatically includes estate user rights
2. Create the access control CSV file
Create:
estate/security/ir.model.access.csv |
Add this content:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
This means:
- estate users can read, create, and edit properties, but cannot delete them
- estate managers can do everything on properties
- only estate managers can manage property types
3. Load security files from the manifest
Update __manifest__.py and add these files to the data list:
{ |
Order matters here. Load groups before ir.model.access.csv because the CSV references those groups.
4. Upgrade the module
Run:
cd ~/odoo-dev/odoo |
If the CSV or XML contains invalid references, Odoo will fail during module upgrade.
5. Assign users to groups
In Odoo:
- Open
Settings. - Open
Users & Companies > Users. - Open a test user.
- Under access rights, assign either
Estate UserorEstate Manager.
Using separate test users is strongly recommended. Do not test everything with the administrator account because admin bypasses many practical permission scenarios.
6. Add a simple record rule
Access rights decide what operations a user can perform on a model. Record rules decide which records they can access.
Create another file:
estate/security/estate_rules.xml |
Add this rule:
<odoo> |
This rule does not restrict anything yet because the domain is empty, but it gives you a correct starting point for understanding the structure of a record rule.
Add it to the manifest after the groups file:
'data': [ |
Upgrade the module again.
7. When to use ACLs and when to use record rules
Use access rights when you want to answer:
- can this group read this model?
- can this group create records on this model?
- can this group delete records on this model?
Use record rules when you want to answer:
- which records can this user see?
- which records can this user edit?
They solve different problems and are often used together.
8. Common security mistakes
Putting everyone in the same powerful group
This defeats the purpose of role-based access control. Keep user and manager roles separate.
Forgetting to load the security files in the manifest
If the files are not in data, Odoo will never load them.
Wrong XML or CSV order in the manifest
Referenced records must be loaded before the file that uses them.
Testing only with admin
The administrator account can hide real security problems. Always test with a non-admin user.
9. Safe next steps
As the module grows, you can add more restrictive rules, for example:
- agents only see properties assigned to them
- only managers can delete sold properties
- some fields are only visible to managers
Odoo also supports field-level group restrictions when needed.
Final words
Your module now has a basic but correct security layer.
In the next article, we will make the module usable by adding menus, actions, list views, and form views.
Previous article: Part 2 - Models and Fields
Next article: Part 4 - Menus, Actions, and Views
Related posts
- /article/odoo-custom-module-development-part-2-models-and-fields/
- /article/odoo-custom-module-development-part-4-menus-actions-and-views/
- /article/odoo-custom-module-development-part-6-reports-demo-data-and-tests/
- /article/odoo-custom-module-development-part-5-relations-computed-fields-and-business-logic/
- /article/odoo-custom-module-development-part-1-create-your-first-module/