Odoo 16 Development Book

Model Attributes

These are the features that are defined during the time of the creation of a new model or using the model which are already existing. Let us see the model attributes in Odoo

_auto = false - Whether we create a new database table that is set to False, override init() to create the database table. It automatically defaults to True for models and Transient models and False for Abstract models.

_log_access - Whether the ORM should automatically generate and update the Access Log Files. Defaults to whatever value was set for _auto.

_table = None - if _auto, it is the SQL table name used by the model.

_sequence = None - SQL sequence, which is used for an ID field.

_sql_constraints = [] - SQL constraints [(name, sql_def, message)].

_register = False - registry visibility by default is false.

_abstract = True - To check whether the model is an abstract model.

_transient = True - To check whether the model is a Transient model.

_name = None - the name of the model.

_inherit = () - we use the inherited attribute when we want to use a model that is already in the database.

_description = None - informal name of the models.

_inherits = {} - dictionary {‘parent_model’: ‘m2o_field’} mapping the _name of the parent objects to the names of the corresponding foreign key fields to use.

_rec_name = None - used for labeling records. By default, it is the name of the record.

_order = ‘id’ - Default order field for searching results.

_check_company_auto = False - On write and create, call _check_company to ensure companies consistency on the relational fields having check_company=True as an attribute.

_parent_name = ‘parent_id’ - The many2one field used as parent field

_parent_store = false - Set to True to compute parent_path field.

_date_name = ‘Date’ - used for default calendar view.

_fold_name = ‘fold’ - used to determine folded groups in kanban views.

Scaffold command

In Odoo, it is the process of creating a skeletal structure for a module. We can automatically design module structures using Odoo scaffolding. It saves lots of time. A module is usually a directory within a module directory. The addons path specifies the module path. Let us see how it can be done. For that, first, let us build a new module under /opt/odoo/custom add-ons, such as custom add-ons. In order to create a module structure, first of all, we must go to the Odoo-bin location using the terminal.

Enter the scaffold command to create a sample module structure. The command is given below.

./odoo-bin scaffold module_name folder_name

module_name: Name of the module

folder_name: Directory name inside which you want to create the module.

Normally, Within a module directory, a module is a directory. The addons path specifies the module path. In order to begin, create a new module in /opt/odoo/custom addons, For example, custom addons. For creating a module structure, we must first go to the odoo-bin location using the terminal. In order to automatically generate a module structure, run the following command given below:

./odoo-bin scaffold new_module custom_addons

By executing the above command, it creates a new module with some directories.

odoo Development

Expanded view of the module.

odoo Development

Each module contains two required python files i.e., ‘__init__.py’ and ‘__manifest__.py’ files.

As we can see in the above image, each directory inside the module will be created by itself. It is possible to make changes to the content that is required.

1. The python files contained within the module are models.

2. Views are the XML files that help to display the records.

3. Data consists of demo data that are needed in the module. It contains XML that creates/updates databases.

4. The security file consists of configured files of access rights.

5. The __init__.py file imports all the python files defined in the module.

6. We use controllers when we need to render data to the website.

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