Odoo provides a wide range of field types that establish relationships between models and manage data efficiently. Among these, Automatic Fields and Reserved Fields play crucial roles in how models function and interact within the system.
In this blog, we’ll explore what Automatic and Reserved Fields are in Odoo 19 and how they help in maintaining data integrity and model relationships.
What Are Automatic Fields?
Automatic fields are system-generated fields that Odoo creates and manages internally. Developers don’t need to define these fields explicitly; they are added by default to every model. These fields help track essential metadata, such as creation dates, update timestamps, and user activities.
What Are Reserved Fields?
Reserved fields are field names that are predefined and reserved by the Odoo framework. These names should not be reused for custom fields to avoid conflicts or unexpected behavior. These fields typically store system-level data like audit logs, metadata, or identifiers.
Common Automatic and Reserved Fields in Odoo 19
Id
The id field represents the unique identifier for each record in a model. This field is automatically created by Odoo for all models and ensures that every record can be uniquely identified. Once a record is created, its id value cannot be modified.
To view this field, you can enable Developer Mode and navigate to View Fields in the interface.
create_date
The create_date field stores the exact date and time when a record is created in the database. This field is automatically managed by Odoo and cannot be changed by the user. It’s particularly useful for filtering records by creation time or for generating reports that depend on creation dates.
write_date
The write_date field captures the date and time when a record was last updated. Every time a record is modified, this field is automatically updated. It serves as a valuable tool for auditing and tracking recent changes within a model. Like create_date, this is a read-only system field.
create_uid
This field is a Many2one relation to the res.users model and stores the ID of the user who originally created the record. Automatically set during creation, the create_uid field helps track user actions, making it useful for auditing, permissions, and workflow control. It is a system-managed, read-only field.
write_uid
Similar to create_uid, the write_uid field is a Many2one relation to res.users. It stores the ID of the user who last modified the record. Automatically updated during every write operation, this field aids in tracking user activity, enforcing access rules, and understanding data changes in detail.
Access Log Fields
Fields such as create_uid, create_date, write_uid, and write_date are collectively known as Access Log Fields. These are only tracked when the model has _log_access = True, which is the default behavior for persistent models.
In transient models (like wizards), log access is generally enabled as well. However, for simple models where tracking changes isn’t needed, setting _log_access = False can disable this behavior and reduce unnecessary database usage.
Name
The name field is typically a required Char field used to label and identify a record. This field is often displayed as the main title in form, tree, and search views. It must be explicitly defined in each model.
Example:
# -*- coding: utf-8 -*-
from odoo import fields, models
class MyModel(models.Model):
_name = 'my.model'
_description = 'Custom Model'
name = fields.Char(string='Name', required=True)
This field plays a vital role in helping users distinguish between records visually in the interface.
Active
The active field is a Boolean field used to control the visibility of a record. When set to False, the record becomes invisible in views and searches, though it still exists in the database. This is useful for temporarily deactivating records without deleting them.
Example:
active = fields.Boolean('Active', default=True)
It’s a standard way to implement soft deletion in Odoo.
State
The state field is a Selection field commonly used to manage the status or workflow of a record. It allows defining various stages like "draft", "approved", "done", or "cancelled", and helps control logic during state transitions.
Example:
state = fields.Selection([
('draft', 'Draft'),
('approved', 'Approved'),
('done', 'Completed'),
('cancel', 'Cancelled'),
], string='State', default='draft', store=True)
This field is especially useful in models such as sales orders, tasks, or manufacturing processes.
company_id
The company_id field is a Many2one relation to the res.company model. It links a record to a specific company in a multi-company setup. This ensures that all records are correctly scoped based on the current user's company, maintaining data isolation and integrity across companies.
Example:
company_id = fields.Many2one(
'res.company',
string='Company',
default=lambda self: self.env.user.company_id,
help='Company associated with this record'
This field is essential for managing operations in environments where multiple companies share the same Odoo instance.
Conclusion
In Odoo 19, Automatic and Reserved fields play a foundational role in ensuring models are well-connected, traceable, and secure. Understanding how these fields function enables developers to create better-structured modules, maintain data consistency, and enhance system performance.
By respecting these system fields and leveraging their built-in functionality, developers can take full advantage of Odoo's powerful ORM framework.
To read more about What are Automatic & Reserved Fields in Odoo 18, refer to our blog What are Automatic & Reserved Fields in Odoo 18