How to store in a field different values per company

In multi-company mode, there are cases when one field would need to store different values for each company.

An example of such fields are some of the accounting settings per product, such as Income Account and Expense Account.

In order for a field to be able to store different values per company it is required in the field definition to be set the attribute company_dependent​ to True​.

Part of the definition of the standard_price​ field which is another example in Odoo of such a field is shown below:

standard_price = fields.Float(
    string='Cost',
company_dependent=True, )

While from a user perspective, this functionality depends only on one parameter, the technical side of it is a bit more complex. These fields do not store their values in the related model’s table. Instead, they are using the ir.property​ table for that. When the value is set in the field, the backend will try to find an existing ir.property​ record that matches the model’s record, field and company. If there is no one it will create a new record with the following information:

  • name​: The name of the field
  • fields_id​: The ID of the field that holds the value
  • res_id​: The ID of the related model’s record
  • company_id​: The ID of the company
  • value_​: The value will be stored in one of the available value fields, depending on the type of the field. For example, the standard_price​ field's value will be stored in the value_float​ column.

Company-dependent fields are searchable and when a value is requested for them the system queries the ir.property​  table.

The list of all company-dependent values can be found at Settings > Technical > Parameters > Company Properties​, developer mode needs to be activated in order to see the Technical menu.