Fields Parameter In Odoo17

In Odoo, field parameters are used to define the characteristics and behavior of fields in models (database tables). Here are some common field parameters in Odoo:

(1)String:

The “String” parameter specifies the human-readable label for the field.

Example:

name = fields.Char(string=’Name Of the field’)

(2)Store:

The “Store” parameter is used to store the field in the database. By default, Most fields are stored in a database. For the computed field you have to specify the parameter store=True.

(3) Readonly:

The “Readonly” parameter is used to make a field read-only. If this parameter is used in the field it can be readonly user can not make any changes in the field value. By default, the parameter value is False.

Example:

name = fields.Char(string=’Name of the field’, readonly=True)

(4) Required:

The “Required” parameter is used to make a field required. If this parameter is used in the field it can be required which means this is the mandatory field you have to assign value.

Example:

name = fields.Char(string=’Name of the field’, required=True)

The “Related” parameter is used to make a field relatable. This means it can make a relation with another field and allows the current field to display values from the related field.

(6) Help:

The “help” parameter is used to add a tooltip that provides additional information about the field.

Example:

name = fields.Char(string=’Name of the field’, help=’Enter the name’)

(7) Copy:

The “Copy” parameter is used to indicate whether the field's value should be copied when duplicating a record. By default, it is True For some fields it is False.

(8) Translate:

The “translate” parameter is used to make a translatable for different languages.

Example:

name = fields.Char(string=’Name Of the field’, translate=True)

(9) Depends:

The “Depends” parameter is used to define dependencies between fields, specifying which fields trigger a re-evaluation of the current field's value when they change.

(10) Groups:

The “groups” parameter is used if you want to restrict the fields for some user then you can use it. For example, if you add a group of managers on the student fees field then the manager can only access this field user can not.

(11) Compute:

The “Compute” parameter is used to specify a method that dynamically computes the field's value based on other fields.

(12) Inverse:

The “Inverse” parameter works with compute, providing a method to update other fields when the computed field changes.

(13) digits:

The “Digits” parameter is used to set the number of decimal places for numeric fields.

(14) Tracking:

The “tracking” parameter tracks changes made to a specific field in the system. It is used in conjunction with the mail. thread model, which enables tracking of changes and notifications for specified fields. The tracking parameter can be set to ‘onchange’, which means that the field’s visibility will be tracked every time an ‘onchange’ function is triggered. This is useful for keeping a record of changes made to the field, as well as who made the changes and when they were made.

(15) PreCompute:

The “precompute” field parameter is used in computed fields to compute value before Record Create.

(16) Ondelete:

The ‘Ondelete’ parameter is used to specify the behavior of a relationship when the related record is deleted.

‘set null’ :

Set null is used when the related record is deleted, and the foreign key field in the current record is set to ‘False’

‘cascade’

Cascade is used when the related record is deleted, all records that have a foreign key relationship to it are also deleted.

‘restrict’

restrict is used when the related record is deleted, Odoo will raise an error and prevent the deletion.

‘set default’

set default is used when the related record is deleted, and the foreign key field in the current record is set to its default value.

(17) Selection:

This parameter is used to define a list of values if u want to define a standard you can use selection.

(18) Selection_add:

When you inherit the selection field and you want to add values in the fields you can use the selection_add parameter.

(19) index:

indexing is a viral strategy essential for enhancing database performance in odoo17. It entails the development of specific database indexes on chosen fields, greatly improving the speed and efficiency of database queries, particularly in scenarios involving extensive datasets.

Example:

company_id = fields.Many2one(‘res.company’, string=’company’, index=True)