Enable Dark Mode!
what-is-automatic-and-reserved-fields-in-odoo-16.jpg
By: Mily Shajan

What Is Automatic & Reserved Fields in Odoo 16

Technical Odoo 16

Odoo has several types of fields that can be used to create relationships between different models and manage access to data. Fields help to create and connect the bonds between the models in Odoo. Automatic and Reserved fields are two types of fields that can be used for this purpose.

Here, in this blog, let’s discuss what are Automatic and Reserved fields and how they help to create the relationship between models.

Automatic fields are fields that are automatically generated by Odoo and do not need to be defined explicitly in the model. For example, the "id" field is an automatic field that is automatically generated and assigned a unique value for each record in the database. Reserved Fields are fields that are reserved by the system and cannot be used as custom field names. These fields are typically used for system-generated information or metadata.

Let’s see each field in detail.

Odoo.fields.id 

This field is used to represent a database column that stores the unique identifier (ID) for a record in a model. Each record has its own id as a unique one. It cannot be edited once the record is created. This Identifier field is useful to identify each record as specifically.

This field can be viewed by enabling debug mode 

Open Debug Mode > View fields 

Odoo.fields.create_date

The Odoo.fields.create_date is a system-defined field in Odoo that is used to store the date and time when a record is created in the database. It is an automatic field that is automatically generated and managed by the system, and cannot be modified by the user.

Odoo.fields.write_date

This field is used to represent the date and time of the last update of a record. When a record is updated, the value of this field is automatically updated to reflect the date and time of the update. This field can be used to filter records based on when they were last updated, or to display the last update date and time on the record form or report. This field is stored as read only one in each record.

Odoo.fields.create_uid

This is a many2one field of comodel ‘res.users’, which stores the user_id who creates the record. This field is automatically set when a new record is created and it is a system field that can be used to track the user who created a particular record, which can be helpful for auditing and debugging purposes. It can also be used to enforce access controls, such as allowing only certain users to create records of a particular type. This is also a read-only one.

Odoo.fields.write_uid

This is also a many2one field of comodel ‘res.users’, which stores the user_id that makes the latest modification in the record. This field is automatically set whenever a record is updated, and it is a system field.

The write_uid field can be used to track the user who made changes to a particular record, which can be helpful for auditing and debugging purposes. It can also be used to enforce access controls, such as allowing only certain users to update records of a particular type and it represents the date and time of the latest modification that occurs in the record.

Access Log Fields.

These fields are also automatically created and updated where log_access is true.

They can be used to track changes to records and to identify who made those changes.

If log_access is disabled, it avoids creating or updating the fields in the tables that aren’t needed. Log_access is true in a transient model and those models store data temporarily and can delete periodically.

Odoo.fields.name

This field is a necessary one on each model of Char Type. It displays the name of each record. This field is commonly used to store names of objects or entities in the system, such as customers, products, or employees.

For example,

from odoo import models, fields
class MyModel(models.Model):
    _name = 'my.model'
    _description = 'Model'
    name = fields.Char(string=' Name', required=True)

Here in this my.model, the name field is defined, which is used to identify and distinguish the record from others in the model. This field is typically displayed as the main label for the record in various views and forms, such as tree views, search views, and form views.

Odoo.fields.active

This field enables the visibility of the view. Odoo.fields.active refers to a Boolean field that is used to mark records as active or inactive. When a record is marked as inactive, it is effectively "hidden" from most views and reports, but the record data still exists in the database and can be retrieved and reactivated later if necessary. This is often used as a way to temporarily disable records without deleting them completely.

active = fields.Boolean('Active', default=True)

When the active field is set as True, records will be visible in views and reports.

Odoo.fields.State

This field type represents a selection field used to define a state or status for a record in a model which is typically used to track the progress or workflow of a record through various stages, such as "draft", "approved", "cancelled", "completed", etc. Each state value is defined as a tuple containing a string label and a unique identifier.

state = fields.Selection([
   ('draft', 'Draft'),
('approveed','Approved'),
   ('done', 'Completed'),
   ('cancel', 'Cancelled'), ], 'State', default='draft',
   store=True)

This field helps define various actions or behaviors that are triggered when a record transitions from one state to another.

Odoo.fields.company_id

This field supports  multi-company functionality. It refers to a field type that represents a many-to-one reference field used to link a record in a model to a specific company. This field allows multiple companies to use the same Odoo instance while keeping their data and configurations separate.

company_id = fields.Many2one('res.company', string="Company", help='company',
                            default=lambda self: self.env.user.company_id)

Odoo.fields.company_id ensures that transactions and documents are properly assigned to the correct company which is a many2one type of model ‘res.company’. These are the examples of some Automatic and Reserved fields in Odoo 16. 


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



0
Comments



Leave a comment

 


whatsapp
location

Calicut

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

location

Kochi

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

location

Bangalore

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

Send Us A Message