In Odoo can be found multiple different methods for filtering and searching records. Each of them is designed with their own uniqueness which makes it more useful in certain cases than others, even though sometimes it may be confusing which one is the right to use. In this post we will go through some of the most used lookup methods and focus on when each of them should be used.

We will cover the following methods:

  • browse
  • search
  • filtered
  • filtered_domain

Browse

The method browse​ returns a recordset for the provided IDs​ in the current environment. In case the method is called without any ID​ it will return an empty recordset. This method creates recordset for the IDs without fetching the actual data immediately from the database. It is useful to use when list of IDs need to be converted into recordset.

Search

The search​ method can accept multiple arguments:

  • domain​: A list of domains to be searched by. An empty list will return all records
  • offset​: Number of results to ignore. Usually used during page pagination
  • limit​: Maximum number of results to return
  • order​: Specified order of records

This method based on the provided arguments creates a search query that is executed in the database and the result from it are stored in memory.

The return from this method is recordset as well. The difference between this recordset and the one from the browse​ method is that this method is doing immediate query to the database and retrieves the data for the selected records, which means when a field is accessed, the value is taken from the memory instead of doing read in the database. The search method has a few additional optimization methods such as search_count​, search_read​ and search_fetch​.

Filtered

The filtered​ ​method as an argument accepts a function or a dot-separated sequence of field names. This method filters records on an already existing recordset, which is one of the differences compared to the previous two methods. The filtering in this method is done on python level and does not use database queries. 

Filtered Domain

Similarly to the filtered​ method, the filtering is done on the existing recordset. The difference is that in this case the argument is a domain, the same format as the one for search​, instead of a function. Depending on the complexity of the domain, the method may execute an actual search to do the proper filtering. However in most of the cases it filters the records in python by evaluating the domain. This is good in case the recordset is already fetched from the database and it is needed some additional filtering which is easier to express in a domain format.

Conclusion

To sum up, the browse​ method is used when there is list of IDs​ but we need a recordset for more convenient handling in the rest of the codebase. 
In case we have some parameters on base of which we need to query the database and get recordset then search​ method is the one that should be used. 
However, if we already have the recordset and need to do some additional filtering on it the filtered​ and filtered_domain​ methods are the right choice. Which one of these methods needs to be used mostly depends on the conditions that need to apply. In case of a simpler condition filtered would be more convenient to use but in case the conditions are more complex can be easier to translate them in a domain format and use filtered_domain​.

These suggestions are based on the assumption that the amount of data handling is moderate. In case of complex domains and bigger amounts of data may need to be done additional evaluation which method would perform the best for such case.


Odoo 17 Odoo 18 Technical
Posts

Sale Financial Risk module extends the Account Financial Risk by providing control of the customer’s credit limit in the sales order. This allows the system to include the financial risk check at the initial phase of the sales process and prevent a quote from being confirmed if the credit limit for the customer is exceeded.

Once the module is installed in the partner’s "Financial Risk" tab can be found two additional fields: “Include Sales Orders” in the General Limits and “Limit Sales Orders” in the Specific Limits.

Financial Risk Tab

When the “Include Sales Orders” is selected, the Sales Orders risk amount will be included in the customer’s Total Risk. The sales order risk amount is a sum of the sales orders’ total amount which is not invoiced. On quote confirmation, the system will check if the total risk exceeds the total credit limit specified for that customer. In case it is exceeded a warning message will be shown.

Additionally, it is possible to specify a specific limit for the sales orders in the field “Limit Sales Orders”. If the field is set, on quote confirmation it will be checked if the specific limit exceeds the total of the quote’s total amount and sales orders’ risk amount. If it does a warning message will be shown with info that the sales orders limit is exceeded.

Furthermore, in the Accounting / Invoicing Configuration Settings can be found the option “Include orders in done state”. This option extends the range of orders used in the financial calculations, not only to orders with the state “Sale Order” but it adds the orders with the state “Locked” as well. This option can be very useful for business cases where the "Lock Sales Order" option is used. 

The warning message that is shown on quote confirmation, when any of the specified credit limits exceeds, can be overpassed by the Financial Risk Manager user. However, for other users, the confirmation will be blocked while the credit limit issue is not resolved.

Similarly to other Financial Risk limits, this module provides a convenient way of overviewing the financial data that contributes to the sales order financial risk.
By clicking on the total sale order risk amount will open the “Financial Risk Information” view where are listed all commercial partners related to the customer, that have an impact on the total risk amount, with information about their risk amounts and quantities. On click of the risk amount on any of the lines will open a list view with all sales order lines which are part of the calculation.

This module is a great addition to the Account Financial Risk module making the financial risk management for sales orders more convenient to implement by covering a wider range of business cases.

The module is maintained by the Odoo Community Association (OCA).

Accounting Functional Sales
Modules Review

Many2many and One2many fields in Odoo require a specific syntax for manipulating related data. The instructions mainly consist of 3 elements added in a tuple, where each of the elements has a special meaning.

The first element is an integer number ranging from 0 to 6. each corresponding to a different action. The associated actions for each numerical value are:

  • 0: Create
  • 1: Update
  • 2: Delete
  • 3: Unlink
  • 4: Link
  • 5: Clear
  • 6: Set

The second element for Update​, Delete​ and Unlink​ is the ID​ of the record to which the action applies while for the rest of the actions: Create​, Clear​ and Set​ this element is with value 0​.

The third element for the first two actions (Create​ and Update​) is the values​ used to create or update the record. For the next four, this element can be left out. The last action Set​, requires a list of IDs​ as a third element. The IDs​ represent the related records. This command replaces the existing relations with the newly supplied list of records’ IDs​.

In addition, is the complete tuple for each action:

  • Create: (0, 0, values)
  • Update: (1, ID, values)
  • Delete: (2, ID)
  • Unlink: (3, ID)
  • Link: (4, ID)
  • Clear: (5)
  • Set: (6, 0, IDs)

Knowing the logic for the elements in the tuple makes it much easier to understand how to create any action without memorizing the list of tuples. However, from version 15, Odoo made this even easier. Now there is a class helper Command​ that is creating the whole tuple. 

The commands for each action are listed below:

  • Create:  Command.create(values)
  • Update: Command.update(ID, values)
  • Delete:  Command.delete(ID)
  • Unlink: Command.unlink(ID)
  • Link:  Command.link(ID)
  • Clear: Command.clear()
  • Set: Command.set(IDs)

Where values​ represent a dictionary of values, ID​ is an integer value of the record’s id in the database and IDs​ is a list of related records ids in the database.

As an example, we will try to modify the tags related to a sales order. Initially, the sales order has only one tag added to it. That tag is with ID1​.

Create:

If the requirement is to add another tag to the sales order which is not presented in the database needs to be used the create​ command:

sale.write({tag_ids: [Command.create({"name": "Tag 2"})]})

this will create a new tag and will add it to the order.

Update:

In case the name of the newly added tag needs to be updated the update will look like this:

sale.write({tag_ids: [Command.update(2, {"name": "Updated Tag 2"})]})      
Delete:

If the new tag is not needed anymore and needs to be removed from the relation with the sale order but at the same time from the database as well should be used the delete​ command.

sale.write({tag_ids: [Command.delete(2)]})
Unlink:

If the requirement was only to remove the tag from the sales order but still to be available in the database then the command unlink​would be the right one.

sale.write({tag_ids: [Command.unlink(2)]})      
Link:

If the tag with ID 3 that already exists in the database needs to be added to the sale order, then link​ is the correct command to use.

sale.write({tag_ids: [Command.link(3)]})
Clear:

In case the tags are not needed in the order and need to be removed from it, instead of going over the whole list and using unlink​ it can be done at once with the clear​ command.

sale.clear({tag_ids: [Command.clear()]})
Set:

The last case is when the current tags, with ID1​ and 3​, which are already added to the order need to be replaced with tags, with ID4​ and 5​, which are in the database but not related to the order.

sale.write({tag_ids: [Command.set([4, 5])]})

The end result after this command will be sales order with tags with IDs4​ and 5​.

Odoo 17 Odoo 18 Technical
Posts

In the post The importance of correctly setting priority on inherited views we have already discussed the importance of the priority​ field in the inherited views and why it needs to have the right value. 

However, in some cases, it may be needed to update the priority of an existing view to meet certain requirements. The simplest case for that can be a request to change the primary view for a model that has multiple views from the same type.

The code sample below presents a way to modify the priority for an existing view from the codebase. In the particular example, the priority of the  view_order_tree​ view in the sale module is updated to value 5​. 


<function model="ir.ui.view" name="write" eval="[ref('sale.view_order_tree')], {'priority': 5}"/>

That would mean that in the system the list view with the biggest priority for the sale.order​ model will be view_quotation_tree​, which has a priority of 4​, and that one will be used always when the list view is not explicitly specified in the action.

Odoo 17 Odoo 18 Technical
Tips

In the native version of Odoo, it is possible to set a Credit Limit per customer, however, it is limited only to setting the Credit Limit amount and showing Informative messages on the Sales Order and Invoice in case the limit is exceeded for the selected customer. 

This functionality is not sufficient in many cases and a more comprehensive solution is needed. Functionality that will provide more control over the financial risk but at the same time flexibility in setting up and detailed overview of it. The module that allows all these is the Account Financial Risk module.

Security

From a security perspective, the module has two access groups User and Manager. The User group allows a read-only access to the Financial Risk data.

The Manager group, on the other side, allows full access to the Financial Risk functionality. Additionally, the users with this group can overpass partner risk exceptions during Invoice confirmation. However, this group is not enough to see the tab Financial Risk in the Customer form view. That means to have full access to the features from this module it is required to have both Financial Risk Manager and Billing Administrator/Accountant groups. The accounting group is controlling the view of the Financial Risk tab.

Financial Risk Tab

Once the module is installed in the system the tab Financial Risk can be found in the Partner form view. The Tab contains a complete overview of the financial risk for the particular customer.

Financial Risk Tab

On the left side can be found the General Limits section which contains the type of credit limits that can be included in the Customer’s Financial Risk, together with the current amount for each of them. The available types of credit limits are:

  • Draft Invoices
  • Open Invoices/Principal Balance
  • Unpaid Invoices/Principal Balance
  • Other Account Open Amount
  • Other Account Unpaid Amount

Unpaid Invoices/Principal Balance type by default includes move lines with account same as the customer’s receivable account which are not reconciled and their due date is passed.
However, the module introduces an option of specifying additional margin before a move line is considered as Unpaid. This configuration is per company and can be found on the accounting configuration page under the name Maturity Margin. The value specified for this setting represents the number of additional days before a move line is considered unpaid.
"Other Account" limit types are move lines with account different than the customer’s receivable account which are with not past date or passed respectively. The Maturity Margin is taken into consideration for the Other Account Unpaid Amount as well.
At the bottom of the General Limits section, there is info about the Risk Remaining and the Total Risk for the customer, which is a sum of all included limits for that customer.

On the right side, can be found the Specific Limits section. In this section can be specified different limits for each type of credit limit.

Additionally, in the Info section it is possible to set a general credit limit per Customer. This limit is overpassed when the total amount that the customer owns from the selected General Limits is bigger than the set credit limit. Furthermore next to the Credit Limit is available the date when it was last updated.
Also in this section can be set the Credit Limit Currency. The available options for it are the following:

  • Company Currency
  • Receivable Currency
  • Pricelist Currency
  • Manual Credit Currency.

In case of selecting the Manual Credit Currency, an additional currency field is shown where the needed currency can be selected. Another available field in this section is Credit Policy, which is only informative and is not used anywhere in the system.

Invoice Confirmation

In case a customer exceeds a certain limit on confirmation of an Invoice “Partner risk exceeded” modal is shown. If the user has the Financial Risk Manager group there is an option in the modal to overpass the Risk Exception and continue with the Confirmation. Otherwise, the Confirmation will be blocked until the Financial Risk Exception for the customer is resolved.
Additionally for cases where this type of limitation is not needed there is a setting that allows invoices to be confirmed for customers with exceeded credit limits by all users that have access rights to confirm invoices. This feature can be enabled by selecting the option “Allow invoice validation over the risk” on the invoicing/accounting configuration page.

Financial Data Overview

The module allows a simple way of overviewing the financial data that is contributing to the current financial risk calculation for a customer. By clicking on the number next to each type of general limit will open the “Financial Risk Information” view, from which can be opened the list of Account Move Lines that are contributing to the Financial Risk for each account. This view can be opened by clicking on the number next to the name of the account.

This module is a great addition to the existing accounting features in Odoo. However, It is only related to the accounting part of the system and will not limit any action related to the Sales Order. In case such a feature is needed, a great addition to this module is the Sale Financial Risk module.

The module is maintained by the Odoo Community Association (OCA).

In addition is a short video with the module’s features.



Accounting Functional
Modules Review


The technical menu can be found on the settings page and it is visible only in developer mode. The menu contains more than 16 sections, some of which are visible only if a particular application is installed. For example, the “Calendar” section is shown only if the “Calendar” module is installed.

Instead of going over all options available in the menu, We will try to provide a broad understanding of the types of configuration options and data that can be found there. This way will be more clear where to look the next time when need to find a specific setting or data in the system.

Organization

The submenus in the Technical menu are typically organized into well-named sections that make it intuitive for users to find the appropriate submenu. The available sections may differ based on the installed modules, but the following are commonly found:

  • Discuss
  • Email
  • Phone / SMS
  • Actions
  • IAP
  • User Interface
  • Database Structure
  • Automation
  • Reporting
  • Sequences & Identifiers
  • Parameters
  • Privacy
  • Resources
  • Calendar

While many of the sections in the menu are self-explanatory, some may require more attention. Therefore, we will focus on those and provide a brief overview of them.

Features

The features that the Technical menu provides, similar to the features in the Developer Mode, can be divided into two main groups:

  • Configuration settings and
  • Data overview and modification

Configuration Settings

The Technical menu contains a wide range of system configuration options. Here are some of them:

  • Setting up Outgoing and Incoming email servers
  • Creating or modifying email and SMS templates
  • Creating or updating scheduled actions that will be executed on a predefined period
  • Creating different automation actions based on conditions.
  • Configuring the "System Parameters." Some of these parameters are also available for editing in a more user-friendly format from other parts of the system.
  • Configuring company resources
  • Setting up different In-App Purchase (IAP) accounts

Data overview and modification

In addition to the system configuration options, the Technical menu also provides access to and an overview of important data in the system. This makes it easier to understand the system and manage it directly from the user interface. The data available in the Technical menu can be divided into two main categories:

  • Technical data
  • Functional data

Technical Data

Technical data refers to the data that is crucial for the proper functioning of the system. The submenus that hold some of the most important technical data are:

  • Models: This submenu provides an overview of the data models defined in the system, along with information about their attributes, related fields, access rights, record rules, and views.
  • Fields: This view lists all the fields specified in the system. It is particularly helpful when the name of the field is known, but the model is not. For each field the​re can be found information about its related attributes.
  • Views: It contains all the available XML views and provides information about their definition and related attributes. Under the view definition, are specified all the fields that need to be shown in the view, their placement as well as additional attributes. Using the attributes can be applied different rules for the elements in the view, for example, they can make a field required, visible or hidden, read-only or editable, etc.
  • Actions: They define the behavior of the system in response to the user's actions. In Odoo there are several different types of actions including "Window Actions", "Server Actions", “Client Actions”, "URL Actions", "Report Actions", and “Automated Actions”. For most of these actions are available separate submenus
  • Menus: All the menus defined in the system can be found in this submenu. The menus usually trigger an action in the system which depending on its type can open a particular view or trigger some other part of the application
  • Access Rights and Record rules: These are essential components of Odoo's security system and ensure that each user can only see the data that corresponds to their profile.

It is important to note that the “Models” and “Fields” cannot be edited from the user interface, while the changes done to the “Views”, “Actions”, and “Menus“ might be overridden when the module is updated. However, the Access Rights and Record Rules can be edited, and their updates will be permanent in most cases.

Functional Data

The functional data available from the Technical menu includes data created by the users and the system as a result of user actions. Here are some examples of such data:

  • Messages: All different types of messages created in the system are listed in this view.
  • Followers: The view provides a complete overview of all followers related to all models in the system.
  • Emails: All sent and scheduled emails can be found here. However, it should be noted that if the "Auto Delete" option is selected in the email template used for the email, it will be auto-deleted once sent.
  • Activities: This view lists all existing activities created by the users in the system.
  • Attachments: All attachments created in the system can be found in this view.
  • Identifiers: All external XML ids which are related to data in the system are listed under this submenu.
  • User-defined filters: All custom filters saved from the user interface can be found in this view.

Conclusion

The technical menu is divided into multiple sections. It contains different configuration options and important data related to different aspects of the system. The data that can be found in this menu can be divided into two main categories: Technical data and Functional data. Technical data is essential for the proper functioning of the system and is largely created from the codebase. Functional data, on the other hand, is generated by users or the system as a result of user actions. Some of the key submenus with Technical data include Models, Fields, Views, Actions, Menus, Access Rights, and Record Rules, each providing insights into specific technical aspects of the system.

Functional Odoo 17 Odoo 18 Technical
Posts


The sequence of loading the views in Odoo is critical in the inheritance mechanism. The changes in the views are always applied following their order by priority​ and ID​. This means the views with the same priority will always be ordered by the ID​ that they have in the database. This makes the order of installing the modules in the database important for properly loading the views. In general, this is a problematic approach because not always we can have control over the sequence the modules are installed, especially when the system has multiple external modules from different sources. Basically, that is why sometimes some view modifications can work in some instances while failing in others.

In order to have more control over the sequence of loading the views in the system it is added priority​ field. Setting up the right value in this field can prevent many of the issues related to inheritance.

The value for the priority​ field mainly depends on three key factors:

  • The view that needs to be inherited,
  • The existing inheritance that the base view has
  • The requirements for the new view

In most of the cases having the biggest priority for the new view can be the right choice, however, there are cases when this is not the best option. Therefore it is always important to do a detailed analysis of the original view and its existing inheritance and on base of that to decide where to insert the new view in the process.

A common issue with view inheritance is when an element from the base view is removed in one of its inherited views while in the new view, this element is used as a position attribute. In this case, if the new view is added with the biggest priority​ value the server will start to complain because the element is removed from the base view before the changes for the new view are applied.

The priority of a new view can be set in the following way:

<odoo>
    <record id="view_order_form" model="ir.ui.view">
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
		<field name="priority">18</field>
        <field name="arch" type="xml">
            <!-- Here goes the customization part -->
        </field>
    </record>
</odoo>

The same things related to priority apply when working with QWeb templates. The priority​ value for a new QWeb templates can be set as shown in the example below:

<odoo>
	<template id="products_description" inherit_id="website_sale.products" priority="55"><!-- Here goes the customization part -->
    </template>
</odoo>

The priority​ of a view can be updated from the UI using the "Views" menu in Settings or "Edit View" option in Developer Mode. The label for the priority​ field is "Sequence".

Odoo 17 Odoo 18 Technical
Tips

The Web Responsive module offers multiple visual improvements for better UI/UX experience in the community edition.

The module has well-documented features that help users understand what it offers.

The list of features is divided into three groups based on device screen size:

  • Universal Features
  • Mobile-Specific Features
  • Desktop-Specific Features

Universal Features

Once the module is installed, it is immediately noticeable that the navigation menu has changed to a full-screen app menu. Additionally, a quick menu search is added at the top, which is auto-focused on desktop screens. This change makes navigation through the system quicker and more convenient.

Furthermore, users can set the default view after logging in to be the full-screen app menu. This can be done by selecting the option Redirect to Home​ in the Preferences tab of the User form view. The User form view can be accessed via Settings > Users & Companies > Users​.

The next few improvements in this group focus on list and form views. In the list view, both the header and footer are made sticky. By default, Odoo only makes the header sticky for desktops. This change significantly improves the user experience when scrolling through long list views. Additionally, checkboxes in the list view are slightly enlarged for better usability.

In the form view, the status bar is made sticky, making it accessible for any action without requiring users to scroll to the top of the screen. This feature worked as expected in version 16; however, during our testing, it did not function properly in version 17.

Another useful enhancement is the ability to change the color of the chatter composer when a message is sent to external users. This functionality improves clarity and usability.

Mobile-Specific Features

The features in this section, which are not available in native Odoo 17, mainly focus on optimizing screen space. As part of this optimization, the buttons in the control panel are replaced with icons.

Additionally, the avatar is removed from the chatter when sending a new message. This change creates extra space for the message composer, which is particularly valuable on small screens.

Desktop-Specific Features

For desktop screens, one highly useful feature is the ability to expand form sheets to full width. This creates additional workspace, especially when the chatter is positioned at the bottom. The position of the chatter can be easily adjusted using the Chatter Position module.

Another feature in this group is the ability to preview attachments on the side. Users still have the option to maximize the preview if needed.

The last modification introduced by the module concerns keyboard shortcuts. After installation, the Alt + [NUM]​ shortcuts are replaced with Alt + Shift + [NUM]​. According to the documentation, this change is primarily intended to avoid conflicts with Firefox tab-switching shortcuts. A practical addition is that pressing Alt displays the available shortcuts on the screen, making them easier to use.

Final Thoughts

This module provides valuable features that make working in Odoo even more convenient. However, given the wide array of functionalities, not all features may align with every user's preferences. A potential improvement could be categorizing these features into groups and offering them as optional choices. This way, users could select only the features relevant to their needs.

The module is actively maintained by the Odoo Community Association (OCA), and the latest available version is 17.0.1.1.6, with migration to version 18 in progress.

In addition is a short video with the module’s features.


Functional
Modules Review


Security layers in Odoo

Understanding how the security system works in Odoo is crucial for effectively configuring user permissions and comprehending why certain data may or may not be visible to users within the system. This article provides an in-depth analysis of the security system in Odoo starting with users, groups, and element and data restrictions. 

Users

To better understand the security system in Odoo, we can visualize it as a series of interconnected layers that collectively create a comprehensive security solution.

At the core of the security system is the user layer. Each user is a fundamental component that controls the level of access and privileges for a particular visitor. Every visitor to the system has a corresponding user profile. Visitors who are not logged in are typically assigned to the public user profile. The user's role in the system is defined within their profile, where can be assigned different types of security groups for the user.

A user can access the system by logging in using a standard username and password mechanism. Additionally, for enhanced security, a two-factor authentication process is available.

Groups

The next layer in the security system is known as "Groups," which serve as a bridge between users and the access limitations defined for specific application’s elements or data. Essentially, groups correspond to roles that can be assigned to employees within the system.

Groups in Odoo are structured in a hierarchical manner, which allows the nesting of multiple groups within one another. When a user is assigned to a particular group, they will inherit any related groups as well

For example, in the Sales module, there are three groups created for different levels of access. The first one, "Sales / User: Own Documents Only," is the lowest level and is designed for users with the lowest access rights. The second group, "Sales / User: All Documents," is intended to provide more broad access rights and includes the first group as an inherited group. Finally, the third group, "Sales / Administrator," has the most extensive permissions within the sales application and has the "Sales / User: All Documents" group as an inherited group.

  1. Sales / User: Own Documents Only
  2. Sales / User: All Documents
  3. Sales / Administrator

So If a user is assigned to the first group, "Sales / User: Own Documents Only," they will only have access to that group within the system. However, if they are assigned to the second group, "Sales / User: All Documents," they will automatically inherit the first group as well. Similarly, if a user is assigned to the third group, "Sales / Administrator," the system will automatically assign them to both the first and second groups.

If a group has inherited groups they can be found in the "Inherited" tab of the group’s form view. Within the group form view, also can be found any related menus, views, access rights or record rules assigned to the group as well as any related users. This information can help to understand the level of security access that the group has in the system.

In Odoo, every group can be assigned to multiple users, and conversely, one user can be assigned to multiple groups which allows for flexible management of access rights.

Element Restrictions

Groups are an essential part of the access control system, but they cannot act on their own. They need to be linked to a component in the next layer to fully exercise their power. This layer contains two types of restrictions: 

  • Element restrictions
  • Data restrictions

They are designed to limit users' access to specific elements and data in the system.

Element restrictions are mainly defined in the codebase and can limit the view of buttons, fields, menus, and even entire views can be assigned to a group. This means that only users who are members of the particular group will be able to see that element. For example, only "Sales / Administrator" group may be able to view “Unlock” button in the Sales form view or the “Reporting” menu in the Sales application. Although these types of restrictions are usually defined in the codebase, they can be set from the UI as well, in the menus and views sections.

Data Restrictions

The second type of restriction is related to data models and is used to limit the user access to only the data that they have been granted permission to view, based on their assigned access groups. This type of restriction involves two layers of data control:

  • Access Rights
  • Record Rules.

Access Rights

Access Rights are responsible for the general control of the data stored in the data model. They define whether a user can read/write/create or delete the data related to that model. When defining access rights, it is enough to use the lowest level group, which will then be inherited by other groups. This means that other groups will also have the same access rights.

For instance, users with groups "Sales/Administrator" and "Sales/User: Own Documents Only" will both have the rights to read, create, write, and delete although the access rights are defined only for "Sales/User: Own Documents Only". However, if we take a look into the access rights defined for the “Public” group we can see that most of them have only read permissions because the group is expected to have minimal permissions in the system.

It is crucial to define access rights for each data model and assign appropriate groups to each. While it is possible to define access rights without a group, it is not recommended, especially for models holding sensitive data, as it would make the data accessible to anyone without any restrictions. It is always best to assign a group to every access right and give the minimum required rights.

Record Rules

While Access Rights are applied as a general rule for the entire data in the model, Record Rules filter the data at a more granular level. The Record Rules layer is designed to filter the data in the model based on predefined filters and to show only what a user should be able to see.

For example, let's consider the Sales groups again. A user with the group "Sales/User: Own Documents Only" can only see the sales orders where it is assigned as a salesperson, while a user with the group "Sales/User: All Documents" can see all sales orders in the system. To achieve this, there are two record rules defined.

The first rule is "Personal Orders," which is assigned to the "Sales/User: Own Documents Only" group. The domain in this rule is defined in such a way that records are filtered by the user who is assigned as a salesperson to the order. So the user can see only the orders to which they are assigned as a salesperson as well as all orders with an undefined salesperson.

The second rule is "All Orders," and as the name suggests, nothing is filtered from the records, so all orders can be seen by the users with the "Sales/User: All Documents" group.

Record Rules also have the option to limit different permissions, such as read, create, write, and delete. There may be cases where a user has the right to see the order but cannot perform any other actions on it. For example, “Portal” users can see their own orders, can edit them and remove them but they can not create a new order, so the order needs to be created for them by another user in the system.

If a group is not assigned to a rule, then the rule is considered a global rule and applies to all users. Global rules are mainly used to restrict data between different companies. For example, in the "Sales Order multi-company" rule, users can only see the orders created for the companies they are assigned to.

It is important to understand that global record rules are strict restrictions and cannot be overridden. On the other hand, record rules assigned to groups can further restrict global rules but can also be relaxed by additional group rules. This means that for a user to see a record, all global rules must be met, while for rules assigned to a group, at least one of the rules needs to be met. So, Record Rules apply to all users in that group, but can be extended by additional rules assigned to different groups.

Record Rules filtering process

Returning to the Sales example, users with the "Sales / User: All Documents" group can see all documents, despite also having the "Sales / User: Own Documents Only" group, because the record rule "All Orders" extends the rule "Personal Orders" with an additional domain that allows viewing all orders in the system.

 Conclusion

Every visitor is assigned to a user who is assigned to access groups that are related to both element and data restrictions. Element restrictions control what elements the user can see, such as buttons, fields, views, and menus, while data restrictions limit what data the user can access in the system. There are two layers of data control: Access Rights and Record Rules. Access Rights are responsible for general data control in the data model, while Record Rules filter data at a more granular level.

If a group is not assigned to a rule, the rule is considered a global rule and applies to all users. Global record rules are strict and cannot be overridden, while record rules assigned to groups can further restrict global rules but can also be relaxed by additional group rules.

Functional Odoo 17 Security Technical
Posts