In this tutorial i will be explaining about the default field types that is supported by the Odoo. This will be based on the new api.
Odoo fields can be classified into two different categories basic fields and relational fields. Along with fields we can pass some keyword arguments to define the field much more. Some kwargs are default for every field others are unique to particular field. Now in Odoo all fields are defined as part of the class. Each field represent a column of that model.
Information about the kwargs can be found below. There are also field specific kwargs that i will explain later in this tutorial.
This is Odoo equivalent of static drop down menu. Selection values consist of key value pair of tuples. Value can be either number or string. Selection fields can be used in workflow creation. selection field value can be defined dynamically using a function.
This is for storing the amount in a specific currency. The precision of the monetary fields are taken from the res.currency model,usually there will be a second field to specify which currency to be used.
In the new api compute fields replaces the fields.function. It uses compute kwarg for converting any normal fields to compute fields. The compute keyword argument holds the function to executed for calculating the value of the field. By default these are non editable and non searchable and also non writable. But you can use the specific kwargs defined below for overruling that. Computed values are calculated at runtime and stored in the cache so that it is not needed to recalculate it again. we can use special decorator @api.depends for specifying the fields related to the compute field. It is always wise to add a default value for the compute fields.
There is also a multi parameter in the field function definition it's related to use the same method to return the value of many function fields. It's only used in the old api and not needed in the new api. It's a matter of performance to call the function only one time for all the function fields with the same multi value and when used the function return value it's different to be able to return all the values of the fields using a dict for every id in the list.
Related fields in the odoo is noted by the related kwarg. We can convert any field in to related fields. It will calculate the field value based on a Many2one field. The related kwarg replaces the fields.related field in the old api.
This represents a many to one relation to a model which is same as drop down in html and which can have optional parameters such as ondelete,context,domain etc. in the db level it will store the id of the referencing model and also this will create a db constraint as we mentioned below.By default no db index is created but this can be done using the index =True.
One2many as the name refers, it is a relation to a model,just like a tree and in that we have to specify the model and the fields that we want to display in the one2many.These have no actual representation in the db. Adding a One2many to a model we need to have a Many2one relation in the targeted model and have to specify the many2one field in the one2many field. These are non as comodel_name and inverse_name in the Odoo level but the name is not necessary the position is enough.
This for adding multiple records of another model to the current model. It will not add any new columns to the db instead of that it will create a new table with the ids of the two table like they are linked to each other.The table name is created by Odoo automatically by combining the two table name and adding the suffix _rel this can be overwrite by the relation kwarg as it is more secure, if the corresponding table names are large then the resulting table name will exceed the Postgres limit of 63 character. We can use the predefined widgets in Odoo such as many2many_tags, many2many etc. to alter the way it is displayed.
These are the default fields in Odoo. But we can create and customize any new fields as Odoo is open source and it's code structure is very simple to understand.