You are currently viewing Odoo – Create a new sample module

Odoo – Create a new sample module


This blog will explain the starting steps involved in developing a custom Odoo 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.

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

  • – 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.

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

[ ]


from osv import fields, osv

class book(osv.osv):

_name = ""
_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.

[ ]


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

[ ]

"name" : "Book Module",
"version" : "1.0",
"author" : "Nevpro",
"website" : "",
"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 module list.
Your Book Module is now ready to install. 🙂

For more information on odoo, check other articles.


Leave a Reply

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.