Tuesday, 15 March 2016

Odoo Module Structure [Terminology]

Hello guys how are you, and I hope you will be fine !!! In my previous post you learned how to create database in Odoo. Today you will learn about Odoo Modules and its structure.

What is Module

Odoo modules can either add brand new business logic to an Odoo system, or alter and extend existing business logic: a module can be created to add your country's accounting rules to Odoo's generic accounting support, while the next module adds support for real-time visualisation of a bus fleet.

In other words: "Everything in Odoo thus starts and ends with modules."

Local Modules
Local modules are those; which are placed in addons directory at local machine. When you install a module it will also install its dependencies. An Odoo modules contain a number of elements:



Business Object / Models: Declared as python classes. (for example models.py) | Models

__init.py__: In this file we have to write name of all folder and python files which are to be complied to this module. If any directory or python files is not listed in this file, than those file will be ignored which could result in fatal error. This file is use as the manifest file for any python module its kind of entry point of the python module. (add the entry point of the xyz.py file)

__openerp.py__: In this file we will write all the description of our modules and its properties. Lets discuss each field in detail.

  1. Name, description, version, author and category are used to describe our modules and its version. So each time we make changes  we will increase the version number.
  2. Depends: If our module depend on another modules than we specify that module name in depend. For example if our module depends on this "module_name" we will specify 'depends:['module_name']'.
  3. Data:  Here we specify all of our xml files.

Data Files: XML or CSV files (for example xyz.xml). | Views

Module data is declared via data files, xml file with <record> element.

                <record model="{model name}" id="{record identifier}">
                   <field name="{a field name}">{a value}</field>
        In the above code "model" is the name of Odoo model for the record, "id" is external identifier  it allows referring to the record. And the field element have "name" attribute which is the name of the field in the model.


Controllers: Handles request from web browsers. (for example controllers.py) | Controller