Automatic & Reserved Fields in Odoo 18
In Odoo 18, the two terminologies Automatic fields and Reserved fields are types of fields that the system manages internally for different functionalities. These fields are not usually defined by any developer or user during development. Automatic fields are added by Odoo dynamically based on some models or configurations or according to certain requirements. In contrast, Reserved fields are already reserved and predefined by Odoo for a clear purpose or use in the system. These types of fields are very important for the framework’s smooth operation and functionality since they perform the specified behind-the-scenes function or task without needing much input from developers or end users.
Let us elaborate on those with examples.
1. Automatic fields
The Automatic fields are those fields that are automatically taken care of by Odoo 18 or generated after analyzing the need and configuration settings required for the models that are about to be created. Such types of fields are usually added by the Object Relational Mapping(ORM) which is the bridge between the programming language and the database.
1.1 ID
This automated field is responsible for the exclusive identification of every record in the model. Each record is assigned its own unique ID managed by the system and it stays unchanged in the lifetime of the record. In debug mode, the instance shows this field ID in the URL of the record.
1.2 create_date
The creation date field is the time stamp that indicates when a record was created for the first time. This is purely a system field. This field cannot be modifiable by the users. Since it is automatically added, developers and users do not need to define or modify this field.
1.3 create_uid
This will automatically capture the user that generated the record. This is a Many2one field with co-model as res. users which means it keeps the id of the record creator from the users’ model. Thus, this field will ensure the record will have that information about who created it.
1.4 write_date
This write_date field gives the timestamp for when a record was last modified. Similar to create_date, this is also a read-only field that gets automatically populated by the system whenever there is a change made and saved to any of the other fields for the record.
1.5 write_uid
write_uid This field is yet another Many2one type system-managed field with its co-model being res. users, having the user ID of the last user who modified the record. This field is essential for change tracking as it details the user who performed the last change. Auditing and debugging are quite critical, while access control is enforced when one identifies who has modified the record.
These fields are automatically appended to each model. This is aimed at tracking essential metadata like who created or modified records and when; accountability is kept confirmed for all to who later changes will relate.
1.6 log_access
The log_access attribute is a model-level attribute in Odoo that enables or disables an automatically created log of metadata, such as the date and time of creation and modification, and the person carrying out the activity. By default, it is enabled, and this is why fields such as create_uid, create_date, write_uid, and write_date are automatically added to the database of the model. If developers want to disable this behaviour, they will set log_access=False; now the system won’t add the fields related to creation and modification
There is also flexibility for the use of log_access as an option to determine whether to include or exclude the metadata logging for that particular model.
2. Reserved fields
Reserved fields are fields that are predefined in Odoo 18 for necessary functionalities within the system. These are usually incorporated automatically by ORM and are one of the key components in handling the Odoo framework. Each of them serves a particular purpose and cannot be repurposed for some other function unless the intended functionality coincides with its original purpose. A few of the most popular reserved fields include the following:
2.1 name
Commonly, the name field is one of the most critical and most-used fields, since across various models the value provided in this field will often serve as the default for the _rec_name of the model that is defined. Therefore, it is a very important string in user interactions with objects. This name is visible over many fields, lists, form views, etc., allowing easy referencing of records by end users.
2.2 company_id
In multi-company setups, company_id is essentially a reserved field to identify that each model record is associated with one company. This field is defined as a Many2one relational field with the co-model set to res. company, thus linking one of the companies created in the system. The company_id field allows Odoo to maintain data segregation between different companies concerning data segregation, access control, and reporting on multi-company situations.
2.3 state
The state field is typically a reserved field for representing various stages or statuses of a record within any given workflow/process easily. It is normally implemented as a select field, where each value represents a specific state in the lifecycle of a record. For instance, fields establish the fact that in documents like sales orders, purchase orders, and invoices, it is through them that the transition of a record is monitored. From writing a draft to completing or cancelling, the procedures become enhanced in transparency and control.
2.4 active
The active field is defined as “Boolean” that tells whether the record is “archived” or “active”. A record can be deactivated by the way of defining active=False. Odoo.fields.active. When a record is deactivated, it becomes virtually “hidden” from views and reports, remaining in the database. Database that is not being used is kept permanently stored and can be converted or restored by the user when needed. Archive records are kept under ‘Trash’ until they are deleted permanently.
2.5 parent_path
This field is also a place to store the full hierarchical path of a record, which is the parent_path. It is in string format representing the entire topmost parent to this record. Thus, searching all the descendants of a specific parent becomes easier because there is no need for recursive querying. On top of that, it works best when using much more complicated data hierarchies.
2.6 parent_id
The parent_id field enables the formation of hierarchical relationships in a model. It is a Many2one field that references another record in the same model thereby creating a self-referencing relationship. This field is crucial for storing data in a tree-like manner, which can have a mega parent-child hierarchy (categories, organization chart, or product hierarchy).
Ultimately, Automatic and Reserved fields in Odoo 18 are critical for the maintenance of metadata about records and for the production of core frameworks of the system. They are also closely related to database structure, record management, and operations in the given system. Enlightenment regarding the application and functions of these fields would help in making a clear understanding and ensure that customizations made remain compatible with the Odoo framework to preserve system integrity and functionality.
"Unlock the Full Potential of Your Business with Odoo ERP!"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"
Get a Free Quote