How to Implement company_dependent=True in Odoo?
✅ What is company_dependent=True?
In Odoo, setting a field with company_dependent=True ensures that the field value can differ per company, while still using the same record across companies.
It is especially useful in multi-company environments where shared master data (like products or accounts) needs to behave differently per company for specific fields (e.g., price, taxes).
📌 Real Use Case
Suppose you have a product used across multiple companies, but the cost price or tax varies by company.
You can use company_dependent=True to let Odoo manage separate values automatically per company.
🧩 How It Works
- Internally, Odoo creates ir.property records to store the value per company.
- When you access the field, it fetches the value based on the current company context.
- When writing, it updates the value only for that specific company.
🔧 Example: Multi-company Cost Price
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
standard_price = fields.Float(
string="Cost",
company_dependent=True,
help="Cost price of the product for each company."
)
- standard_price will now have different values per company.
- Accessing it with self.env.company context will return the correct one.
🔄 Setting Values Per Company
# Set cost for company A
product.with_company(company_a).standard_price = 100.0
# Set cost for company B
product.with_company(company_b).standard_price = 120.0
- Values will be isolated per company, using the same product record.
✅ Summary Table
Feature | Behavior |
Field Isolation per Company | ✅ Yes |
Record shared across companies | ✅ Yes |
Stored via | ir.property |
Required context for access | Automatically handled by env.company |
Common fields example | standard_price, property_account_income_id |
⚠️ Important Notes
- company_dependent=True works only for simple field types (e.g., Float, Many2one).
- It should be used only when a field needs to vary by company.
- Do not use it for fields that are meant to be globally consistent across companies.