Managing multiple companies within a single ERP system can be both powerful and complex. Odoo 18 continues to enhance its multi-company architecture, offering robust tools for separating data, streamlining intercompany operations, and ensuring compliance across legal entities. But with great flexibility comes the need for a disciplined approach, especially for developers and technical consultants.
In this blog, we’ll dive into the essential guidelines for implementing and managing multi-company setups in Odoo 18. Whether you're handling intercompany transactions, defining access rules, or customizing company-dependent behavior, this guide will walk you through best practices, technical patterns, and pitfalls to avoid.
Odoo’s ORM includes several built-in mechanisms to effectively handle multi-company operations.
- Company-dependent fields
- Multi-company consistency
- Default company
- Views
- Security rules
Company Dependent Fields
In a multi-company environment, we must sometimes anticipate that when a record is accessible from more than one company, a particular field will be allocated a different value based on which company provided the value. Odoo achieves this using the ‘company_dependent=True’ parameter in field definitions. Company-dependent fields in Odoo are a special type of field that can hold different values depending on the company context in which the record is being accessed. They’re particularly useful when you have shared records (e.g., products, accounts, partners) that need different configurations per company without duplicating the entire record. Here is a sample of field definition with the check_company parameter:-
display_name = fields.Char(company_dependent=True)
We must make sure the company we are using is the right one in order to read the values of company-dependent fields set by a different company than the one we are currently using. The with_company() parameter, which modifies the current company, can be used for this.
As an example, if Company A and Company B are there, User A has access to both companies. Company A is the main company, and User A is selected by that company. While we update the display_name field from Company A, those value is updated to only that company. When we try to access that field from Company B, it will return a different value, which is updated from Company B. The standard_price field is a perfect example of the company_dependent parameter, which stores different costs within different companies for the same product.
Multi-Company Consistency
In Odoo 18, maintaining data consistency across companies is a key requirement in any multi-company setup. Whether you are linking partners to invoices or associating products to stock moves, ensuring that all related records belong to the same company prevents accounting discrepancies, inventory errors, and business rule violations.
To enforce multi-company consistency, we must follow:-
- Set the class attribute _check_company_auto = True. This tells Odoo to automatically validate company consistency during record creation and updates.
- For the relational fields defined within the models that contain the company_id field, we should define them with check_company=True. This activates built-in validation to ensure the linked record belongs to the same company.
Once these are in place, Odoo will automatically validate the company relationships during every create() or write() operation.
Default Company
Setting a default company is a recommended practice when a model requires the field company_id. Doing so provides several benefits:
- It automatically assigns the correct company context when new records are created, especially in backend scripts, automated actions, or wizards.
- It prevents validation errors caused by missing company_id values during create() operations.
Here is an example of these:-
company_id = fields.Many2one('res.company', default=lambda self: self.env.company, required=True)
The default company is mainly helpful when the company field is hidden (for non-multi-company users); the only way to ensure that new records are valid is by assigning a default value. Without it, creation will fail since the required field is missing, but the user has no way to provide it in the UI.
Security Rules
In a multi-company environment, security rules are crucial to ensure that users only access the data belonging to companies they are authorized to work with. Odoo uses security rules based on company_ids, which contain the current companies of the user to enforce this.
As an example:-
<record id="res_partner_multi_company_rule" model="ir.rule">
<field name="name">Partners of user's companies</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="domain_force">[('company_id', 'in', user.company_ids.ids)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record>
This rule means:
- Only partners whose company_id is in the list of companies that are allowed for the logged-in user will be visible
- This rule applies to all users in the base.group_user group.
Odoo 18 makes handling multiple companies in one system both powerful and manageable. By using features like company-specific fields, automatic checks to ensure records belong to the right company, and default values for easier record creation, we can reduce errors and improve efficiency. Security rules help ensure that users only see the data from the companies they’re allowed to access.
Following these multi-company guidelines will help us to keep our data clean, organized, and secure. Whether we’re creating records, customizing views, or writing rules, understanding how Odoo’s multi-company tools work will save time and help our system scale smoothly as our business grows.
To read more about How to Manage Lead/Opportunity in Multi-Company Setup in Odoo 16?, refer to our blog How to Manage Lead/Opportunity in Multi-Company Setup in Odoo 16?