Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 39 ยท Security and Access

Access Rights with ir.model.access

Learn Odoo model access rights: the ir.model.access.csv file, read write create unlink permissions per group, the missing-file warning and how to test access in code.

Groups say who someone is. Access rights say what each group may do with each model. In Odoo they are rows of the model ir.model.access, and almost every module ships them in one small CSV file, security/ir.model.access.csv. If a model has no access rows, ordinary users cannot touch it at all, which is a safe default.

The Odoo files and ORM calls below are read-only. The runnable parts are Python stand-ins for the logic.

The CSV file

TEXT
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_library_book_user,library.book user,model_library_book,library.group_library_user,1,0,0,0
access_library_book_manager,library.book manager,model_library_book,library.group_library_manager,1,1,1,1

Reading it column by column:

  • id: the external ID of this access row. It must be unique within the module.
  • name: a label for people.
  • model_id:id: which model. The name is always model_ plus the model name with dots replaced by underscores (library.book becomes model_library_book).
  • group_id:id: the group the row applies to, written module.group_xml_id. Leave it empty to grant the right to every user, including portal and public.
  • perm_read, perm_write, perm_create, perm_unlink: 1 or 0 for each of the four CRUD operations.

The file is listed in the manifest data key. It must be loaded before views that rely on the access, and the groups it names must be defined in an earlier file. A usual order is: security groups XML, then ir.model.access.csv, then record rules, then views.

Python
"data": [
    "security/library_security.xml",
    "security/ir.model.access.csv",
    "views/library_book_views.xml",
],

How rights combine

Access rights are additive. A user holds many groups, and for each operation Odoo checks whether any matching row, from any of the user's groups or the global rows with no group, grants it. There are no "deny" rows. So a Manager group that implies User gets the union of both.

flowchart TD
    A["Action: write on library.book"] --> B{"Any access row for the<br/>user's groups, or global,<br/>with perm_write = 1?"}
    B -- No --> C["AccessError"]
    B -- Yes --> D{"Record rules<br/>allow this record?"}
    D -- No --> C
    D -- Yes --> E["Operation runs"]

Model access comes first, record rules (next lesson) come second. Both must pass.

The "no access rules" warning

If you create a model and forget the CSV file, the server logs a warning at install: the model has no access rules, so nobody except the superuser can use it. Many developers see this as a reminder, not an error, but a model with no rows is unusable for normal users. When you create a transient model for a wizard, access rows are not needed because transient models have their own rules.

Checking access in Python

Python
# Raise AccessError if the current user cannot do it
self.env["library.book"].check_access("write")        # Odoo 18+
# older: check_access_rights("write")

# Return a boolean instead of raising
if self.env["library.book"].has_access("unlink"):
    ...

# Same idea for a recordset (rules included)
books.check_access("read")

An AccessError is shown to the user as a friendly "You are not allowed to..." dialog. Catching it in code is rare; usually you let it bubble.

Stand-in: an access checker

The stand-in below loads CSV text with the standard csv module, builds the table, and answers "may this user do this?" by taking the union across the user's groups.

Python Evaluate access rows

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Raising and catching AccessError

Here the same logic wraps an operation, so you can see how a failed check stops the work before anything is changed.

Python Guard an operation with an access check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Wrong external ID. model_library_book must match the model's _name exactly. A typo gives an error at install time.
  • Missing group prefix. In the CSV a group from the same module still needs the module name, as in library.group_library_user.
  • Forgetting the file in the manifest. It silently does nothing.
  • Too wide global rows. An empty group_id row gives everyone (even the public website visitor) that permission.
  • Testing only as admin. Administrators can mask missing rows. Create a test user with just your module's group.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In ir.model.access.csv, what does an empty group_id mean?

    A global row has no group and grants its permissions to everyone, so use it with great care.
  2. 2. How are the model_id values named for the model library.book?

    Model external IDs are model_ plus the dotted name with dots replaced by underscores.
  3. 3. Can an access row deny a permission that another row grants?

    There is no deny. To restrict, give the permission only to the groups that need it.
  4. 4. What happens if a model has no access rows at all?

    No rows means no access for normal users, which is the safe default, and the log shows a warning.

Summary

  • Access rights are rows of ir.model.access, usually from security/ir.model.access.csv.
  • Each row names a model, an optional group, and four permissions.
  • Rights are additive across groups; there are no deny rows.
  • No rows means normal users cannot use the model; an empty group means everyone can.
  • Record rules add a second, row-level layer.

Next: Record Rules