What do Automatic and Reserved Fields signify in Odoo 17?

Odoo incorporates various field types aimed at establishing relationships between different models and controlling data access. These fields are pivotal in establishing connections among models within Odoo. Among these types, automatic and reserved fields are particularly instrumental in fulfilling this objective.

This blog will delve into examining Automatic and Reserved fields, elucidating their significance in enabling the establishment of relationships between models.

In Odoo, Automatic fields are generated automatically by the system without needing an explicit definition in the model. For instance, the 'id' field is automatically generated, offering a unique value for each database record. Conversely, Reserved fields are predefined by the system and cannot be utilized as custom field names. These fields are primarily reserved for system-generated data or metadata, fulfilling specific functions within the system.

Now, let's delve deeper into each field.

Identifier

The field 'id' in Odoo serves to represent the database column designated for storing a unique identifier (ID) for every record within the model. Each record is assigned its own unique ID upon creation, which remains immutable thereafter. This identifier is crucial for accurately distinguishing individual records. To access and view this field, you need to enable debug mode and navigate to "Show fields."

Creation Date

This is a predefined field in Odoo intended to hold the date and time when a record was created in the database. As an automatic field, it is created and managed by the system and cannot be altered by the user.

Modification Date

This attribute denotes the date and time of the record's most recent modification. Whenever a record is edited, this attribute is automatically refreshed to reflect the corresponding date and time. It serves to filter records based on their latest update timestamp and to showcase the last modification date and time within a record form or report. Stored as a read-only attribute, it cannot be altered within each record.

User ID of Creator

This is a many-to-one field linked with the 'res.users' comodel, storing the user_id of the record creator. Automatically filled when a new record is created, this system field helps in tracing the user who created a particular record, which assists in auditing and debugging processes. Additionally, it facilitates access control by limiting record creation to designated users. This field is set as read-only.

User ID of Last Modifier

This field, a many-to-one relation with the 'res.users' comodel, stores the user_id of the most recent record modifier. Known as write_uid, it is automatically refreshed upon any record modification, facilitating tracking of the user behind the latest alterations. It serves essential roles in auditing and debugging, also enabling access control enforcement by limiting record updates to designated users. Furthermore, it denotes the date and time of the record's last modification.

Fields for Access Logging

These fields are automatically created and refreshed when log_access is enabled. They are employed to track alterations made to records and to pinpoint the users accountable for those changes.

By deactivating log_access, unnecessary creation or updating of these fields in tables where they're not needed is avoided. Normally, log_access is activated in transient models, which temporarily store data and are subject to periodic removal.

Title

This attribute is compulsory for every character-type model. It serves to showcase the title of each record and is frequently utilized to store labels for various entities within the system, such as customers, products, or employees.

As an example:

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


In the preceding illustration, the 'name' field is specified within the 'my.model' class, serving as a vital component in distinguishing and identifying records within the model. Typically, this field serves as the principal label for records across various views and forms, including tree views, search views, and form views.

Enabled

This attribute governs the visibility of the view. The https://odoo.fields.active/ indicates a Boolean field used to designate records as active or inactive. When a record is marked as inactive, it essentially becomes "hidden" in most views and reports. Nonetheless, the recorded data persists in the database and can be retrieved and reactivated at a later time if necessary. This functionality is frequently utilized as a method to temporarily disable records without permanently deleting them.

Illustration:

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

In this scenario, if the active field is set to True, the records will appear in views and reports.

Status

This field type represents a selection field utilized to specify a state or condition for an item within the model. It's frequently employed to monitor the progress or workflow of a record as it advances through different stages like "draft", "submit", "cancel", and others. Each state value is defined as a tuple containing a string label and a distinctive identifier.

For instance:

state = fields.Selection(
   selection=[
       ('draft', 'Draft'),
       ('posted', 'Posted'),
       ('cancel', 'Cancelled'),
   ],
   string='Status',
   required=True,
   readonly=True,
   copy=False,
   tracking=True,
   default='draft',
)

In this scenario, the 'state' field assists in defining different actions or behaviors that occur when a record moves from one state to another.

Organization ID

The company_id field in Odoo enables multi-company functionality, serving as a many-to-one reference field that links a record in a model to a particular company. This feature enables multiple companies to utilize the same Odoo instance while maintaining their data and configurations distinct from one another.

For example:

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

company_id guarantees precise allocation of transactions and documents to their corresponding companies. It is classified as 'many2one' type and references the 'res.company' model. The provided example illustrates the utilization of automatic and reserved fields in Odoo 17.

Installing Odoo 17 on Windows