Enable Dark Mode!
By: Hridhya D

An Overview of Field Parameters in Odoo16

Technical Odoo 16

The attributes that can be assigned to fields that are defined within models are called Field parameters. Commonly used field parameters in Odoo are string, required, readonly, store, help, etc.

String - The name of the field viewed by the user. If the string is not specified, the ORM uses the class's field name.

name = fields.Char(string="Name of the field")

Help -Tooltips are displayed to users in the UI. 

name = fields.Char(string="Name", help="Enter the Name")

Invisible -We can make a field invisible by giving invisible=True. By default invisible is False.

Translate -We can make a field translatable by giving translate=True. It can carry a variety of values depending on the user interface language.

name = fields.Char(string="Name", translate=True)

Readonly - Giving readonly=True to a field will make it read-only. By default, read-only is False.

name = fields.Char(string="Name", readonly=True)

Required -We can make a field required by giving required=True. The Required attribute by default is False.

name = fields.Char(string="Field name", required=True)

Store - A field can be made storable by setting store=True. By default, the Store is True, but in computed fields, by default, the Store is False.

Copy - It decides whether the field value should be copied when a record is duplicated. Standard fields have this attribute set to True by default, but one2many and computed fields, such as property fields and related fields, have it set to False by default.

Groups - It allows us to restrict field access to specific user groups 

name = fields.Char(string='Name', groups="base.group_user")

Index - Indexing refers to the process of creating database indexes on specific fields to enhance the performance of database queries. Indexing can improve the speed of filtering, sorting, and searching operations on those fields (indexing plays a crucial role in optimizing the performance of database queries)

True or "btree": This is the default index type used for many2one relationships. 

field_name = fields.Many2one('model.name', index=True)

"btree_not_null": This index type is similar to the "btree" index but excludes NULL values. It is useful when a significant number of values in the field are NULL or when NULL values are not frequently searched for.

field_name = fields.Char(index="btree_not_null")

"gin" or "trigram": These index types use Generalized Inverted Indexing (GIN) with trigrams. They are suitable for full-text searches and can improve search performance when dealing with textual data. 

field_name = fields.Text(index="gin")

False or None: This indicates that no index should be used on the field. By default, if the "index" attribute is not specified, Odoo assumes it to be False. 

field_name = fields.Integer(index=False)

Default -We can specify the default value for a field in a model. Static Value: You can assign a fixed value to the "default" parameter. This value will be entered as the field's default value whenever a new record is created. 

field_name = fields.Char(default='Default Value')

In this case, whenever a new record is created, the field "field_name" will have the value 'Default Value' by default. 

Callable Function: Instead of a static value, you can assign a function to the "default" parameter. This function returns a value after accepting a recordset as a parameter. The recordset represents the current record(s) being created or modified.

def compute_default_value(self): 
# Perform some computation or logic 
return computed_value 
field_name = fields.Integer(default=compute_default_value)

In this example, the function compute_default_value calculates and returns a computed value based on some logic. This value will be set as the default value for the field "field_name" when a new record is created. 

default=None: Setting default=None indicates that no default value should be applied to the field. It effectively discards any default values for the field. 

field_name = fields.Boolean(default=None)

In this case, no default value will be assigned to the boolean field "field_name" when a new record is created.

States - You can create a dictionary that converts state values to lists of UI attribute-value pairs by using the "states" attribute. The possible attributes that can be used within this dictionary are "readonly," "required," and "invisible." These attributes help control the behavior and visibility of fields based on the current state of the record.

state = fields.Selection([ ('draft', 'Draft'), 
('confirmed', 'Confirmed'), ('done', 'Done')], 
string='State', default='draft', states={ 'confirmed': 
[('readonly', True)], 'done': [('readonly', True)] } )

Compute - the "compute" attribute is used to define computed fields. Computed fields are fields that do not have a direct value stored in the database but are instead calculated or derived based on the values of other fields or through a custom logic defined in a Python method 

Precompute –whether to compute the field before inserting the record into the database. 

recursive (bool) – whether the field contains recursive dependencies (the field X has a dependency similar to parent_id.X); a field's recursive declaration must be explicit in order to ensure that recomputation is accurate.

inverse (str) – the name of the technique to reverse the field

search (str) – the name of a technique that is used for field search 

related (str) – sequence of field names

selection - This field's possible values are specified. It can be given as a list of pairs (value, label), a model method, or the name of a method.

selection_add - In the case of an overridden field, gives an extension of the selection. It is a list of either pairs (value, label) or singletons (value,), with singleton values required in the overridden selection. The new values are added in the following order, which is compatible with the override selection and this list: 

selection = [('a', 'A'), ('b', 'B')] 
selection_add = [('c', 'C'), ('b',)] 
> result = [('a', 'A'), ('c', 'C'), ('b', 'B')]

ondelete – gives any field with a selection_add that has been overridden a fallback method. Every choice from the selection_add is mapped to a fallback action in this dict. All records with a selection_add option mapping to it will have this fallback action applied to them. The following are examples of possible actions: 

’set null’ – the default, the selection value for every record using this option will be False.

’set null’ – the default, the selection value for every record using this option will be False.

’cascade’ – By selecting this option, all associated records will be permanently removed from the system, and the option itself will also be deleted. 

’set default’- All records will be reset to the default values specified in the field definition

’set VALUE’ – The specified value will be applied to the all records option 

<callable> –A callable for custom processing with a single argument, which is the set of records containing the specified selection option.

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message