Odoo – Create a new sample module


This blog will explain the starting steps involved in developing an Odoo custom module. It is just like a “Hello World” kind of guideline, therefore you won’t be able to get all the theories behind the Odoo. Instead, you will get all the necessary information to start off with. Similarly, the sample module given here is fully functional and tested on Odoo 8.

Odoo – Create a new sample module

Module Description

The sample module described here is a simple Book application. It also helps to take down Books and contains just three fields namely “Title”, “Description” and “Author” in its data model.


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.

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

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

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

  • __openerp__.py – is the module descriptor file.

File Contents

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 ERP module. This will handle the core functionality of the module. It also will generate the database table to store related data.

[ book.py ]


from osv import fields, osv

class book(osv.osv):

_name = "book.book"
_description = "Simple Book"
_columns = {
‘title’ : fields.char(‘Title’, size=30, required=True),
‘desc’ : fields.text(‘Description’),
‘author’ : fields.char(‘Author’, size=30, required=True),

Next we will import the above python file we created in module initialization script.

[ __init__.py ]


import book

After that we define the view and also menu structure of our module.

[ book_view.xml ]

<?xml version="1.0" encoding="utf-8"?>
<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"/>

<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"/>

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

<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"/>

Finally create the Odoo module descriptor as follows.

[ __openerp__.py ]

"name" : "Book Module",
"version" : "1.0",
"author" : "Nevpro",
"website" : "http://www.nevpro.co.in",
"category" : "Tools",
"depends" : ["base"],
"description" : "Book - Simple demo module",
"update_xml" : ["book_view.xml"],
"installable": True

That’s all you need, now start the server and upgrade the module list.
Your Book Module is now ready to install. 🙂

Odoo ERP is the best ERP software for manufacturing and therefore the best ERP solutions for small business. We offer customization and implementation of ERP system. Nevpro business solutions is one of the top ERP Development companies worldwide.

For more information on odoo, check other articles.

Leave a Reply