Tags

, , , , ,


Module Structure

An Odoo module consists of some basic elements. Note that what is explained here is only the basic files required to develop a module and structure will be more complex in actual real world applications.

__init__.py – init script will load the application’s main python-module and related in application initialization.

__openerp__.py – is the module descriptor file.

module_name.py – a class, contains the application logic and database table structure definition.

view_name.xml – contains the application interface definition and menu structure.

First Create a new folder in addons directory of server as “book” and add following files.

There is no specific order, I am going to start with the main python class (module) of our Odoo module. This will handle the core functionality of the module and also will generate the database table to store related data.

__init__.py

import book

__openerp__.py

{
‘name’ : ‘Book Module’,
‘version’ : ‘1.0’,
‘author’ : ‘ananthu’,
‘website’ : ‘http://www.odoo.com’,
‘category’ : ‘Tools’,
‘depends’ : [‘base’],
‘description’ : ‘Book Simple demo module’,
‘update_xml’ : [‘book_view.xml’],
‘installable’: True
}

book_view.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<openerp>
<data>
<record model=”ir.ui.view” id=”book_tree_view”>
<field name=”name”>book.tree</field>
<field name=”model”>book.book</field>
<field name=”type”>tree</field>
<field name=”arch” type=”xml”>
<tree string=”Book”>
<field name=”title”/>
<field name=”desc”/>
<field name=”author”/>
</tree>
</field>
</record>

<record model=”ir.ui.view” id=”book_form_view”>
<field name=”name”>book.form</field>
<field name=”model”>book.book</field>
<field name=”type”>form</field>
<field name=”arch” type=”xml”>
<form string=”Book”>
<field name=”title”/>
<field name=”desc”/>
<field name=”author”/>
</form>
</field>
</record>

<record model=”ir.actions.act_window” id=”action_book_form”>
<field name=”name”>book</field>
<field name=”res_model”>book.book</field>
</record>

<menuitem name=”Book” id=”book_menu”/>

<menuitem name=”Book Group” id=”book_group_menu” parent=”book_menu”/>

<menuitem name=”Books” parent=”book_group_menu” id=”book_menu_mainform” action=”action_book_form”/>
</data>
</openerp>

book.py

from openerp.osv import fields, osv
from openerp.http import request

class book(osv.osv):
_name = “book.book”
_description = “Simple Book”
_columns = {
‘title’ : fields.char(‘Title’, required=True),
‘desc’ : fields.text(‘Description’),
‘author’ : fields.char(‘Author’, required=True),
}

 

 

 

Advertisements