Restricting records in Odoo with record rules

Record rules decide which individual records a user can read, write, create or delete inside a group's access rights. This page explains how to scope them, combine them and test them before they reach production.

On this page

How Odoo record rules restrict records by group

A sales representative should see only their own quotations, or a warehouse team should see stock for one site only. In Odoo, record rules filter individual records for each group of users. Access rights answer a different question. They decide whether a group can read, write, create or delete records of a given model at all. Record rules decide which rows of that model the group can reach once access is granted. Teams usually need record rules when the same model holds data that different people should not share, such as several companies in one database, several warehouses, or sales teams that must not see each other's pipeline. If a role is only separated by app menus, access rights alone are often enough.

In Odoo, a record rule is defined as a domain on a model, which is the same filter syntax used in search views. A rule may be global, applying to every user, or attached to a group, applying only to members of that group. The domain is evaluated by the Odoo server when it builds a query, so the filter applies to the self-hosted Odoo server and its ORM, not to the browser. Hiding a button or menu in the web client does not restrict data, and any API call, report or export that reads the model goes through the same rules. Confirm this behavior for each access path your integrations use, including the JSON-2 API.

Before writing rules, map each role to the rows it needs and check how rules combine. Group rules are combined with OR across the groups a user belongs to, while global rules are combined with AND, so a global rule can silently narrow access for every group. Build a test matrix with one user per role and company, and verify counts, search results, linked records and reports, not only the form view. Confirm the rule semantics against the Odoo documentation for your version, and plan performance checks on large tables, because a domain that cannot use an index or that traverses several related models can slow list views and exports. Keep the rule list short and review it during every upgrade or custom module change.

Global versus group record rules

A global record rule has no group assigned, so it applies to every user who accesses the model, including administrators who hold no special groups. Global rules are the place for restrictions that must hold everywhere, such as keeping one company's records out of another company's view in a multi-company database. Because they apply without exception to the users they cover, a mistake in a global rule is felt by the whole organization at once, so review them before changes reach production.

  • Applies to all users: Every user reading or writing the model is subject to the rule, regardless of the groups they hold.
  • Defined without a group: The rule's group field is left empty, which is what makes it global.
  • Best for hard boundaries: Company separation or data-residency style limits fit here because they should not depend on a user's role.
  • Harder to scope back: Adding an exception means editing the global rule or adding a rule that widens access, so keep the domain simple.
  • Illustrative example: A global rule on sales orders limits each user to records whose company is among the companies they are allowed to access.

Before relying on a global rule, check that administrators and automated actions behave as you expect, and confirm the exact rule form, field names and group handling against the Odoo 19.0 developer documentation for the version you run.

Which rule pattern fits which restriction

This table matches common record restriction goals to the rule pattern that usually fits, the groups it affects and the main risk. Read each row as a starting design to test in a staging database before it reaches users. Multi-company cases need separate treatment and are flagged in the table.

Restriction goalRule patternGroups affectedMain risk
Own records onlyGroup rule with a domain such as the record's salesperson or creator equal to the current userSales or service users who should not see colleagues' recordsRecords with an empty owner field disappear for these users, and managers may be locked out without an extra rule
One warehouseGroup rule filtering the stock location or warehouse field against the user's allowed warehousesWarehouse operators assigned to one siteTransfers that span warehouses or lack a warehouse field may be hidden or left unlinked
One company in a multi-company databaseCompany-based domain that checks the record's company against the user's allowed companiesUsers who work for a single legal entityShared contacts and products can leak or vanish; this needs the multi-company access page
Read-only access for a groupGroup rule on the same model granting read permission only, with write and delete access withheld in access rightsAuditors, finance reviewers, branch staff who view but do not editRules only restrict rows, so a broad write right elsewhere still allows changes; check access rights too
Managers see team recordsGroup rule matching the record owner's department or manager, or a parent-child user relationTeam leads and managers in a hierarchyHierarchy data goes stale when staff change teams, so the rule can expose records after a transfer
Global rule as a fenceGlobal rule with a domain that applies to every user, such as company scope, combined with group rulesAll users, including administrators, unless the rule excludes themGlobal rules are combined with group rules using AND, so a narrow global rule can silently hide data from everyone
Sensitive fields on shared recordsRecord rules do not hide individual fields; use field-level access rights and view design insteadUsers who see the record but not its cost or marginTeams assume a rule protects fields and expose costs through reports, exports or the API

How multiple rules combine and where they fail

Odoo combines record rules for the same model and operation in two layers, and the layers do not combine the same way. Global rules, which have no group attached, apply to every user, and their conditions are combined with AND, so each one narrows what a user can reach. Group rules attach to a security group and are combined with OR among themselves, so each group a user belongs to widens access by the records its rule allows. The effective result is the global conditions applied on top of the union of the group rules. That is why a user with two group memberships can see more than either rule suggests on its own, and why adding a group for one job function can quietly expose another company's or warehouse's records.

The most damaging mistake is a global rule written too narrowly. A rule that requires company_id to match the user's current company, for example, applies to every call made through the ORM with a restricted user, including scheduled actions, server actions, imports and integration accounts. Those processes run under a user record, so a rule that assumes an interactive session can silently return empty lists or block writes. The failure often shows up as missing data long before anyone sees an error. Administrators can be affected too when their memberships do not satisfy the global condition, so a test with an admin account may not reproduce what a background job experiences.

Confirm the exact combination logic in the developer documentation for your Odoo version before writing the first rule, because the handling of global rules, group rules and superuser contexts is the detail most likely to change between releases. Then test each role twice: once as a real restricted user, and once as the account that runs your scheduled actions and integrations, comparing record counts with and without the rule. Keep a visibility matrix that lists every group and every overlapping combination of groups, and have your security reviewer sign it off before go-live. Overlaps are easy to miss when each group is tested alone, so test the combinations directly.

How to build and deploy record rules safely

This sequence turns a written access requirement into tested Odoo record rules, so each group sees only the records it should in every screen that reads that data. It ends with a staged rollout that a non-admin account has verified.

  1. Map each restriction to models and groups

    Start from the written access requirement, such as sales reps seeing only their own orders or warehouse staff seeing one site. List each model involved, the field that identifies ownership or location, and the Odoo group that should receive the restriction. Also list who is exempt, usually administrators or a finance group. The step is done when every restriction has a model, a field, a group and a named owner who approved it.

  2. Put the rule in a custom module

    Create or extend a custom module in your development repository rather than editing core files, so the rule is versioned, reviewed and survives updates. Keep the access rights file and the rule data file in the same module. Confirm with your developer which Odoo version the module targets, because record rule XML and domain syntax should be checked against that version's documentation. The step is done when the module installs cleanly on a development database.

  3. Set access rights before adding rules

    Define model access rights for each group first, since record rules only narrow access that a group already has. Check that the groups you plan to restrict have read, write, create or delete permissions only where the business process needs them. Installing the module on a development database and logging in as a user from each group confirms that menus and buttons appear as expected. The step is done when each group's basic access matches the design sheet from step one.

  4. Write the rule with its group and domain

    Add the record rule with a domain that filters on the ownership or location field, and attach it to the target group. Decide whether the rule is global or applies only to that group, and confirm how it combines with other rules on the same model, since Odoo ORs rules within a group and ANDs across groups. Document each rule with a short description of who it covers and why. The step is done when the rules load without errors and appear in the rules list for the model.

  5. Assign test users and cover each group

    Create at least one non-admin test user for each group that the rule affects, plus one user who should see everything, and set their company and group memberships explicitly. Avoid testing with the administrator account, because it bypasses most record rules. Record the expected result for each user on a checklist. The step is done when every test user is assigned, and the checklist lists the records each user should and should not see.

  6. Check every surface as a non-admin user

    Log in as each test user and verify that list views, search, filters, grouped views, exports, chatter messages, linked records, reports and dashboard counts all respect the rule. Pay attention to related fields and smart buttons, which can expose a record count or name even when the detail record is hidden. Try direct URLs to records the user should not see. The step is done when every surface matches the checklist and no restricted record appears through any path.

  7. Retest on staging before production

    Move the module to a staging copy of the production database, using a neutralized copy if you need to avoid emailing real customers, and repeat the checks from the previous step with real group assignments. Compare the results with the expected checklist and log any gaps. Only deploy to production after staging passes and the rule change has an agreed rollback path. The step is done when staging results are signed off and the production deployment record names the module version and the test users used.

How a request is filtered by access rights and record rules

The diagram starts with a signed-in user request and checks group membership first, then model access rights, which decide whether the model can be used at all. Only then do global and group record rules narrow the rows the user can see, and the result is the record set returned to the screen or API. The admin and sudo path sits in its own boundary, because code running with elevated rights skips these checks. When you review a setup, confirm that no custom code takes that path for ordinary user requests.

Request path through group, access right and record rule checks, with the elevated bypass shown apart.

Security risks in record rules

Record rules are the last line of defense between a user and another group's data, and they fail quietly. The risks below share one pattern: a rule looks correct on the screen a tester opens, while another path to the same records skips it. Each card names the check to run before a rule set is trusted.

Related records and reports

A rule on sales orders does not automatically protect the invoice lines, delivery moves, stock quants or PDF reports that expose the same amounts and customer names. A user who cannot open a record can still see its totals in a related list or printed document. Check every model that links to the restricted model, and open each report and smart button as a restricted user to confirm that the same filter applies.

Sudo and raw SQL bypass

Code that calls sudo() runs with superuser rights, and raw SQL queries skip the ORM entirely, so neither path applies record rules. A custom controller or server action that looks correct can expose every row. Search the custom modules and any Apps Store code for sudo() and cr.execute, and confirm each call site filters by the current user's allowed records.

Rules left after module changes

A rule written for one version of a model can stop matching after a field is renamed, a company field is added or a module is upgraded. Odoo does not warn you when a rule domain points at a field that no longer means what it did. Review every rule in custom and third-party modules after each upgrade or model change, and record who owns each rule so changes get reviewed.

Exports and API exposure

A list view can hide a field or a record that the export tool, the XML-RPC or JSON-2 API, or a webhook still returns. Exports and API calls use the same ORM access checks, but a broad permission on the API user can return far more than the screen does. Test each path as a restricted user: export the model, call the API with that user's key, and compare the results with what the web client shows.

Admin accounts masking results

Administrators and users in the wrong groups see records that regular users never see, so a test run as admin shows a clean result that no staff member will experience. Accounts can also hold several groups that add access. Run every test with a dedicated test user that has only the target group, and confirm the user's group list before recording a pass.

How record rules affect performance on large tables

Every record rule adds a domain condition to the queries Odoo builds for that model, so a rule does not sit beside the query, it becomes part of it. On a small table this is invisible. On a table with millions of sales lines, stock moves or journal entries, the extra condition can change how long a list view, a search, a group-by or a report takes to return. Odoo applies the rule to reads and searches for every user in the affected group, which means the cost lands on the screens your busiest users open most often.

The shape of the condition matters as much as the rule's purpose. A condition on a stored field of the model itself, such as user_id or warehouse_id, gives PostgreSQL a direct filter it can satisfy with an index, provided one exists on that column. A condition that follows a chain of many2one relations, such as a rule on order_id.team_id.company_id, forces joins across related tables for every row considered, and the planner has fewer good options. Before you deploy, check which columns your rules filter on, confirm they are indexed where the table is large, and avoid rules that depend on computed or non-stored fields, since those cannot be searched directly in the database.

Do not assume the impact. Build a staging copy with production-scale data, log in as a representative user from each affected group, and time the screens they use most, using Odoo's profiling tools and PostgreSQL's query plans for the slow queries. Compare results with and without the rules enabled, and repeat the test after your indexes are in place. Ask your implementation partner to document the query and timing results in the test record, and confirm any figures in your own environment, since the effect depends on data volume, hardware, database configuration and how many rules apply to the same model.

Limits to confirm in your Odoo version and edition

Record rule behavior, edition limits and upgrade cycles all decide whether a rule set will still work after go-live. The cards below list what to confirm with your Odoo version, hosting plan and change process before you write the first rule.

Rule behavior by version

Record rules are part of the Odoo ORM, so the way they are written, combined and evaluated can change between major versions. Confirm the behavior in the exact version you run, not in the version your examples came from. Odoo 20.0 standard support runs until September 2029, and Odoo 19.0 until September 2028, so a rule set built now may need checking on each major release within that window. Ask your partner to list the version-specific differences they tested.

Support windows

Custom module eligibility

Rules that go beyond the standard apps usually live in a custom module, and that depends on your plan. Only the Custom plan includes custom modules, and it can be hosted on Odoo.sh or on-premise. If your team runs Odoo Online on a lower plan, the rules you planned may not be deployable as designed. Confirm the plan, hosting type and edition in writing before the design phase starts.

Odoo pricing

Studio customizations

Studio lets administrators add fields and views without writing code, and those changes can affect which fields a rule references. A rule that depends on a field created in Studio may behave differently after a Studio edit or when the field is removed. Inventory every Studio change, decide which ones are owned by the security design, and document who may edit them. Treat Studio changes as part of the access model, not as cosmetic work.

Testing after each upgrade

Major upgrades on Odoo Online and Odoo.sh are mandatory every two years, and upgrade tests can reveal changed rule results that never show up in a code review. Keep a set of test users and records for each group, then rerun them against the upgraded test database before production. Record the expected visibility for each user so a failure is easy to spot. Ask your partner whether they maintain this test set as a retainer deliverable.

Mandatory major upgrade cycle
Two years
Upgrade documentation

Edition and upgrade service access

The upgrade service that moves a database to a newer version is tied to the Enterprise subscription for on-premise use, and Community has no access to it. If you run Community, your team will need its own method to port rules and test them. Confirm which edition you hold and how you will upgrade before you commit to rules that depend on Enterprise features or on the upgrade service.

Questions teams ask about record rules

How much effort do record rules take, and who does the work?

Effort depends on how many groups need a different view of the same model, how many companies or warehouses the database holds, and how many custom models sit behind your screens. The work is mostly analysis: mapping who should see what, writing the domain for each rule, and checking that reports, smart buttons and API calls respect the same limits. A partner is paid for that design and for testing, while your own administrators keep the rules afterwards. Ask any quote to list the groups in scope, the models that need rules, the test accounts to be built, and whether custom modules are included.

How long does a scoped record rule set take to build and test?

No fixed duration applies to every database, so treat any single number with caution. The main drivers are the count of groups and personas, the number of models with restricted access, the amount of custom code, and how many companies share data. Testing usually takes longer than writing the rules, because each persona needs to be checked on lists, forms, searches, reports and exports. Ask for a written plan that breaks the work into models, personas and test cases, so you can see where the time goes.

Can our team configure record rules without a developer?

Simple rules can be set up by a trained administrator through the Odoo interface in developer mode, because a rule is a domain expression on a model linked to one or more groups. Rules that depend on computed fields, related paths across several models, or context values usually need a developer to design them and check their performance. Rules in custom modules are normally written in code and shipped with the module. Decide early which rules your administrators own, and document the reasoning behind each one so future changes are safe.

How do we test record rules as a restricted user?

Create a test user for each persona, assign only the groups that persona should hold, and log in as that user on a staging copy of the database rather than production. Check that the expected records appear in list views, search results, reports, exports and linked records, and that records outside the domain cannot be opened by URL or through related fields. Repeat the same checks through the API with that user's API key, since rules apply there too. Keep the test cases in writing so they can be rerun after every upgrade or rule change.

How do record rules change after an Odoo upgrade?

Rules are stored with the database and the modules that define them, so an upgrade can keep them, but the underlying models, fields and default groups may change between major versions. Odoo's upgrade documentation describes an upgraded test database that should be tested before production, which is the right place to rerun your persona tests. Custom rules tied to fields that were renamed or removed need porting work. Your test cases should be part of the upgrade plan, because a rule that silently stops matching is the most common cause of data exposure after an upgrade. Confirm the exact behavior for your target version in the Odoo documentation.

Do record rules alone secure our data?

No. Record rules limit which records a user sees within a model, but they sit alongside access rights, which decide whether a user can read, write, create or delete at all, and alongside the sudo and raw SQL paths used by code. Public controllers, portal access, exports, attachments, and third-party modules can each expose data if they bypass the ORM or the rules. Pair rules with careful group design, a security review of custom code, 2FA, and periodic testing. A penetration test of the application can check whether the rules hold in practice.

What performance effects should we expect on large tables?

Every rule adds conditions to the queries Odoo builds, so a complex domain on a table with many rows can slow list views, searches and reports. The cost grows when rules follow several related models, when they use computed or non-stored fields, or when a user belongs to many groups whose rules combine. Ask for timings on your largest model with each persona, and check the database query plans on staging before go-live. Simplifying the domain, indexing the fields the rule filters on, or moving a check into the access rights layer are common ways to reduce the cost.

How DeployOpen scopes and tests Odoo record rules

DeployOpen starts record rule work with the process owners, not with code. Before any rule is written, the team maps each business object that needs restriction (sales orders, stock moves, invoices, employee records) against the people who work with it, then agrees with each process owner who should see which records, under which condition, and who may override that. The output is a written access matrix that lists each group, the domain condition it should apply, and the records it must never see. Sales managers, warehouse leads and finance controllers each review their own rows. Open questions are resolved here, because a rule that encodes an unsettled decision is expensive to unwind after users depend on it. Confirm early whether any group needs access across companies or warehouses, since that changes whether a rule is global or group-specific.

DeployOpen then implements the agreed model in a custom module that is reviewed like any other code change. Rules are kept in version-controlled data files, each one tied to a named group and a stated purpose, so a reviewer can check the domain expression, the permissions it applies to and any sudo or cross-company behavior in one place. Global rules and group rules are reviewed separately, because they combine differently: group rules that apply to the same model are joined with OR, while global rules are combined with AND. Testing happens on a staging copy of the production database, with restricted test accounts created for each group. The team logs in as those accounts and checks list views, search results, reports, exports, chatter and linked records, including the paths where a user reaches a record through a related field. Each check is recorded with the account, the record and the expected result, so the same suite can be rerun after changes.

Documentation and ongoing review are part of the deliverable. DeployOpen records each rule, its intent and its test cases in a document the client keeps, and notes which rules depend on Odoo internals that may change between versions, so the upgrade team knows where to look first. Access models are reviewed again whenever a new app, company or warehouse is added. Engagements are fixed-scope and agreed in writing before work starts, with the scope, deliverables and timeline stated in the agreement. Teams that want continuing review of rules as the database grows can move to a retainer, which covers ongoing review and retesting rather than a one-off build.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.