Enable Dark Mode!
model-attributes-in-odoo-17.jpg
By: Ruksana P

Model Attributes in Odoo 17

Technical Odoo 17

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. Typically, each model in Odoo corresponds to a distinct database table, encompassing the necessary attributes and behaviors for effective data handling.
Odoo features three primary types of models:
There are three primary model types:
1. Abstract model
2. Transient Model
3. Models
Models
For regular database-persisted models. The fields are declared as attributes within the model.
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class ClassStudent(models.Model):
   _name = 'class.student'
Abstract Model
The primary superclass for conventional database-persisted Odoo models, from which all Odoo models are derived by inheritance,
# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

class ClassStudent(models.AbstractModel):
   _name = 'class.student'
Transient model
Superclass for models designed to represent transient records meant to be temporarily persistent and subject to regular vacuum cleaning.
# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

class ClassStudent(models.TransientModel):
   _name = 'class.student'
Model Attributes in Odoo 17
These features are specified either during the creation of a new model or when utilizing an existing one. Let's explore the model attributes in Odoo.
1. _name 
It corresponds to the model's name. The model name is expressed in dot-notation within the module namespace.
_name = 'student.student'
2. _auto (default = true)
Setting _auto to false indicates whether a new database table should be created. 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.
3. _log_access (default = auto)
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.
4. _table
We can define the SQL table name utilized by the model if  ‘_auto’ is enabled
_table = 'event_track_visitor'
5. _register (default = false)
Register visibility refers to whether a particular class or model should be automatically registered in the system's registry.
6._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.
7. _transient
This attribute determines whether the model is transient or not. By default, it is set to 'true' for transient models and 'false' for regular models and abstract models.
  7.1. _transient_max_count 
    (default= lazy_classproperty(lamda _: cofig.get (‘osv_memory_count_limit’))
    We can declare the maximum records in the transient model. If we set ‘0’, we can store an unlimited number of records.
  7.2. _transient_max_hours
     (default= lazy_classproperty(lamda _: cofig.get (transient_age_limit))
    Lazy class property defined as the maximum idle lifetime in hours, with unlimited duration if set to ‘0’
class PrivacyLookupWizardLine(models.TransientModel):
   _name = 'privacy.lookup.wizard.line'
   _description = 'Privacy Lookup Wizard Line'
   _transient_max_count = 0
   _transient_max_hours = 24
8. _description
We have the option to specify an informal name for the module.
9. _sql_constraints = [ ]
        We can declare the sql constraints as follows,
 _sql_constraints = [( name,sql_def,message)]
10. _inherit = ()
When working with a model that already exists in the database, we employ this attribute for both classical and extension types of inheritance. 
_inherit = ‘product.product’
11. _inherits = {}
Delegation inheritance involves employing the _inherits attribute and matching the ‘_name’ of the parent business objects with the names of the corresponding foreign key fields.
_inherits = {‘parent_model’,’m2o_field}
   _inherits = {
   'a.model': 'a_field_id',
   'b.model': 'b_field_id'
}
12. _rec_name = None
 Utilized for record labeling, the default is the record's name.
13. _rec_names_search = None
 The variable ‘_rec_names_search’ is used to specify the fields considered in the ‘name_search’ function.
14. _order(default = ‘id’)
The default field for ordering search results.
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.
18. _fold_name = ‘fold’
Used to determine folded groups in Kanban views.
19. _active_name = None
Field designated for active records, automatically configured to either "active" or "x_active"
In Odoo, model attributes are used to define the behavior and characteristics of a data model. These attributes provide information about how the model should interact with the database, handle records, and present data.


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