KEMBAR78
Model Attributes in Odoo 18 - Odoo 18 Slides | PPTX
Model Attributes in Odoo 18
Enterprise
Enterprise
Introduction
In this slide, we’ll discuss the Model Attributes in Odoo 18. In
Odoo, a model is essentially a class that represents a specific
data relationship or table. It encapsulates all the essential fields
and functionalities required for storing and managing the
associated data. Model attributes are specified either during the
creation of a new model or when utilizing an existing one.
Enterprise
1. _name
This defines the name of the model and this is mandatory for custom
models and specifies the model's unique name within Odoo. This is
expressed in dot-notation within the module namespace.
eg; _name = ‘privacy.lookup.wizard.line’
2. _description:
Provides a human-readable description of the model. This is used to
describe the model, typically for better understanding in the UI.
eg: _description = 'Privacy Lookup Wizard Line'
Enterprise
3. _inherit:
This attribute inherit fields and behavior from an existing model.
Used to extend the functionality of an existing model without
redefining it completely.
eg: ‘sale.order’
4. _inherits:
This attribute enables delegation inheritance, creating a relationship
with another model while still being a separate model. This allows
using fields from another model by creating a link between them.
eg: _inherits = {'res.partner': 'partner_id'}
Enterprise
5. _rec_name:
Specifies the field used as the display name of the record. This is
useful when you want to display a specific field as the default name in
the user interface.
eg: _rec_name = 'name'
6. _rec_names_search = None
The variable ‘_rec_names_search’ is used to specify the fields
considered in the ‘name_search’ function.
eg: _rec_names_search = ['name', 'full_name']
Enterprise
7. _sql_constraints:
Defines SQL-level constraints on the table, such as unique constraints
or foreign key constraints. This ensures data integrity at the database
level.
eg: _sql_constraints = [('unique_name', 'unique(name)', 'Name must be
unique')]
8. _log_access:
It determines whether the ORM should automatically generate and
update Access Log files. When we are set _log_access = false, the
fields ‘create_date’, create_uid’, ‘write_uid’ and ‘write_date’ is not
automatically populated to database table. Default value for this is
auto.
eg: _log_access = True
Enterprise
9. _auto:
Determines if Odoo should create the corresponding database table
automatically. This is set to False if the table already exists outside
Odoo. If set to false, the init() method needs to be overridden to
manually create the database table. By default, it is True for models
and Transient models, and False for abstract models.
eg: _auto = True
10. _table:
Specifies the name of the database table associated with the model.
This defines a custom table name, useful when avoiding table name
conflicts.
eg: _table = 'custom_table_name'
Enterprise
11. _transient:
Defines a model as transient, meaning it will store temporary data
and be cleared periodically. This is useful for wizard models or short-
lived records.
eg : _transient = True
11.1. _transient_max_count
We can declare the maximum records in the transient model. If we set
‘0’, we can store an unlimited number of records.
11.2. _transient_max_hours
Lazy class property defined as the maximum idle lifetime in hours,
with unlimited duration if set to ‘0’.
Enterprise
On the other hand, setting this value to non zero will unlinks old
records from the transient model tables whenever the
:attr:`_transient_max_count` or :attr:`_transient_max_hours` conditions
(if any) are reached.
12. _order:
Sets the default sorting order of the records. Specifies how records
should be ordered in views or searches. The default value for the
_order attribute in Odoo models is id asc.
eg: _order = 'name desc'
Enterprise
13. _register (default = false)
Register visibility refers to whether a particular class or model should
be automatically registered in the system's registry. If set to False
means it is not visible in ORM registry, it is meant to be python-
inherited only.
14._abstract
This attribute determines whether the model is abstract or not. By
default, it is set to 'true' for abstract models and 'false' for regular
models and transient models.
Enterprise
15. _check_company_auto (default = false)
During write and create operations, invoke the _check_company
function to guarantee consistency among companies for relational
fields with the check_company=True attribute.
16. _parent_name = ‘parent_id’
The many2one field is employed as the parent field.
17. _parent_store (default = false)
The attribute ‘_parent_store’ is set to True to calculate the
‘_parent_path’ field.
Enterprise
18. _fold_name = ‘fold’
Used to determine folded groups in Kanban views.
29. _active_name = None
Field designated for active records, automatically configured to either
"active" or "x_active"
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

Model Attributes in Odoo 18 - Odoo 18 Slides

  • 1.
    Model Attributes inOdoo 18 Enterprise
  • 2.
    Enterprise Introduction In this slide,we’ll discuss the Model Attributes in Odoo 18. In Odoo, a model is essentially a class that represents a specific data relationship or table. It encapsulates all the essential fields and functionalities required for storing and managing the associated data. Model attributes are specified either during the creation of a new model or when utilizing an existing one.
  • 3.
    Enterprise 1. _name This definesthe name of the model and this is mandatory for custom models and specifies the model's unique name within Odoo. This is expressed in dot-notation within the module namespace. eg; _name = ‘privacy.lookup.wizard.line’ 2. _description: Provides a human-readable description of the model. This is used to describe the model, typically for better understanding in the UI. eg: _description = 'Privacy Lookup Wizard Line'
  • 4.
    Enterprise 3. _inherit: This attributeinherit fields and behavior from an existing model. Used to extend the functionality of an existing model without redefining it completely. eg: ‘sale.order’ 4. _inherits: This attribute enables delegation inheritance, creating a relationship with another model while still being a separate model. This allows using fields from another model by creating a link between them. eg: _inherits = {'res.partner': 'partner_id'}
  • 5.
    Enterprise 5. _rec_name: Specifies thefield used as the display name of the record. This is useful when you want to display a specific field as the default name in the user interface. eg: _rec_name = 'name' 6. _rec_names_search = None The variable ‘_rec_names_search’ is used to specify the fields considered in the ‘name_search’ function. eg: _rec_names_search = ['name', 'full_name']
  • 6.
    Enterprise 7. _sql_constraints: Defines SQL-levelconstraints on the table, such as unique constraints or foreign key constraints. This ensures data integrity at the database level. eg: _sql_constraints = [('unique_name', 'unique(name)', 'Name must be unique')] 8. _log_access: It determines whether the ORM should automatically generate and update Access Log files. When we are set _log_access = false, the fields ‘create_date’, create_uid’, ‘write_uid’ and ‘write_date’ is not automatically populated to database table. Default value for this is auto. eg: _log_access = True
  • 7.
    Enterprise 9. _auto: Determines ifOdoo should create the corresponding database table automatically. This is set to False if the table already exists outside Odoo. If set to false, the init() method needs to be overridden to manually create the database table. By default, it is True for models and Transient models, and False for abstract models. eg: _auto = True 10. _table: Specifies the name of the database table associated with the model. This defines a custom table name, useful when avoiding table name conflicts. eg: _table = 'custom_table_name'
  • 8.
    Enterprise 11. _transient: Defines amodel as transient, meaning it will store temporary data and be cleared periodically. This is useful for wizard models or short- lived records. eg : _transient = True 11.1. _transient_max_count We can declare the maximum records in the transient model. If we set ‘0’, we can store an unlimited number of records. 11.2. _transient_max_hours Lazy class property defined as the maximum idle lifetime in hours, with unlimited duration if set to ‘0’.
  • 9.
    Enterprise On the otherhand, setting this value to non zero will unlinks old records from the transient model tables whenever the :attr:`_transient_max_count` or :attr:`_transient_max_hours` conditions (if any) are reached. 12. _order: Sets the default sorting order of the records. Specifies how records should be ordered in views or searches. The default value for the _order attribute in Odoo models is id asc. eg: _order = 'name desc'
  • 10.
    Enterprise 13. _register (default= false) Register visibility refers to whether a particular class or model should be automatically registered in the system's registry. If set to False means it is not visible in ORM registry, it is meant to be python- inherited only. 14._abstract This attribute determines whether the model is abstract or not. By default, it is set to 'true' for abstract models and 'false' for regular models and transient models.
  • 11.
    Enterprise 15. _check_company_auto (default= false) During write and create operations, invoke the _check_company function to guarantee consistency among companies for relational fields with the check_company=True attribute. 16. _parent_name = ‘parent_id’ The many2one field is employed as the parent field. 17. _parent_store (default = false) The attribute ‘_parent_store’ is set to True to calculate the ‘_parent_path’ field.
  • 12.
    Enterprise 18. _fold_name =‘fold’ Used to determine folded groups in Kanban views. 29. _active_name = None Field designated for active records, automatically configured to either "active" or "x_active"
  • 13.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com