Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Odoo Development Essentials
Odoo Development Essentials

Odoo Development Essentials: Fast track your development skills to build powerful Odoo business applications

eBook
$17.99 $25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Odoo Development Essentials

Chapter 2. Building Your First Odoo Application

Developing in Odoo most of the time means creating our own modules. In this chapter, we will create our first Odoo application, and you will learn the steps needed make it available to Odoo and install it.

Inspired by the notable todomvc.com project, we will build a simple to-do application. It should allow us to add new tasks, then mark them as completed, and finally clear the task list of all completed tasks.

You will learn how Odoo follows an MVC architecture, and we will go through the following layers during the to-do application implementation:

  • The model, defining the structure of the data
  • The view, describing the user interface
  • The controller, supporting the business logic of the application

The model layer is defined with Python objects that have their data is stored in the PostgreSQL database. The database mapping is automatically managed by Odoo, and the mechanism responsible for this is the object relational model, (ORM).

The...

Understanding applications and modules

It's common to hear about Odoo modules and applications. But what exactly is the difference between them? Modules are building blocks of Odoo applications. A module can add or modify Odoo features. It is supported by a directory containing a manifest or descriptor file (named __openerp__.py) and the remaining files that implement its features. Sometimes, modules can also be referred to as "add-ons." Applications are not different from regular modules, but functionally, they provide a central feature, around which other modules add features or options. They provide the core elements for a functional area, such as accounting or HR, around which other modules add features. Because of this, they are highlighted in the Odoo Apps menu.

Modifying and extending modules

In the example that will follow, we will create a new module with as few dependencies as possible.

This will not be the typical case, however. The most frequent situation is where modifications or extensions are needed on an already existing module to fit some specific use cases.

The golden rule is that we shouldn't modify existing modules by changing them directly. It's considered bad practice to modify existing modules. This is especially true for the official modules provided by Odoo. Doing so does not allow a clear separation between the original module code and our modifications, and makes it difficult to apply upgrades.

Instead, we should create new modules to be applied on top of the modules we want to modify, and implement those changes. This is one of Odoo's main strengths: it provides "inheritance" mechanisms that allow custom modules to extend existing modules, either official or from the community. The inheritance is possible...

Creating a new module

Our module will be a very simple application to keep to-do tasks. These tasks will have a single text field, for the description, and a checkbox to mark them as complete. We will also have a button to clean the to-do list from the old completed tasks.

These are very simple specifications, but throughout the book we will gradually add new features to it, to make it more interesting for the users.

Enough talk, let's start coding and create our new module.

Following the instructions in Chapter 1, Getting Started with Odoo Development, we should have the Odoo server at /odoo-dev/odoo/. To keep things tidy, we will create a new directory alongside it to host our custom modules:

$ mkdir ~/odoo-dev/custom-addons

An Odoo module is a directory containing an __openerp__.py descriptor file. This is still a legacy from when Odoo was named OpenERP, and in the future is expected to become __odoo__.py.

It also needs to be Python importable, so it must also have an __init__.py file...

Adding to the addons path

Now that we have a new module, even if minimal, we want to make it available in Odoo.

For that, we need to make sure the directory the module is in is part of the addons path. And then we need to update the Odoo module list.

Both operations have been explained in detail in the previous chapter, but we will follow here with a brief overview of what is needed.

We will position in our work directory and start the server with the appropriate addons path configuration:

$ cd ~/odoo-dev
$ odoo/odoo.py -d v8dev --addons-path="custom-addons,odoo/addons" --save

The --save option saves the options you used in a config file. This spares you from repeating them the next time you restart the server: just run ./odoo.py and the last saved options will be used.

Look closely at the server log. It should have an INFO ? openerp: addons paths: (...) line, and it should include our custom-addons directory.

Remember to also include any other addons directories you might be using...

Installing the new module

The Local Modules option shows us the list of available modules. By default it shows only Apps modules. Since we created an application module we don't need to remove that filter to see it. Type "todo" in the search and you should see our new module, ready to be installed.

Installing the new module

Now click on its Install button and you're done!

Understanding applications and modules


It's common to hear about Odoo modules and applications. But what exactly is the difference between them? Modules are building blocks of Odoo applications. A module can add or modify Odoo features. It is supported by a directory containing a manifest or descriptor file (named __openerp__.py) and the remaining files that implement its features. Sometimes, modules can also be referred to as "add-ons." Applications are not different from regular modules, but functionally, they provide a central feature, around which other modules add features or options. They provide the core elements for a functional area, such as accounting or HR, around which other modules add features. Because of this, they are highlighted in the Odoo Apps menu.

Modifying and extending modules


In the example that will follow, we will create a new module with as few dependencies as possible.

This will not be the typical case, however. The most frequent situation is where modifications or extensions are needed on an already existing module to fit some specific use cases.

The golden rule is that we shouldn't modify existing modules by changing them directly. It's considered bad practice to modify existing modules. This is especially true for the official modules provided by Odoo. Doing so does not allow a clear separation between the original module code and our modifications, and makes it difficult to apply upgrades.

Instead, we should create new modules to be applied on top of the modules we want to modify, and implement those changes. This is one of Odoo's main strengths: it provides "inheritance" mechanisms that allow custom modules to extend existing modules, either official or from the community. The inheritance is possible at all levels data models...

Creating a new module


Our module will be a very simple application to keep to-do tasks. These tasks will have a single text field, for the description, and a checkbox to mark them as complete. We will also have a button to clean the to-do list from the old completed tasks.

These are very simple specifications, but throughout the book we will gradually add new features to it, to make it more interesting for the users.

Enough talk, let's start coding and create our new module.

Following the instructions in Chapter 1, Getting Started with Odoo Development, we should have the Odoo server at /odoo-dev/odoo/. To keep things tidy, we will create a new directory alongside it to host our custom modules:

$ mkdir ~/odoo-dev/custom-addons

An Odoo module is a directory containing an __openerp__.py descriptor file. This is still a legacy from when Odoo was named OpenERP, and in the future is expected to become __odoo__.py.

It also needs to be Python importable, so it must also have an __init__.py file.

The...

Adding to the addons path


Now that we have a new module, even if minimal, we want to make it available in Odoo.

For that, we need to make sure the directory the module is in is part of the addons path. And then we need to update the Odoo module list.

Both operations have been explained in detail in the previous chapter, but we will follow here with a brief overview of what is needed.

We will position in our work directory and start the server with the appropriate addons path configuration:

$ cd ~/odoo-dev
$ odoo/odoo.py -d v8dev --addons-path="custom-addons,odoo/addons" --save

The --save option saves the options you used in a config file. This spares you from repeating them the next time you restart the server: just run ./odoo.py and the last saved options will be used.

Look closely at the server log. It should have an INFO ? openerp: addons paths: (...) line, and it should include our custom-addons directory.

Remember to also include any other addons directories you might be using. For instance...

Installing the new module


The Local Modules option shows us the list of available modules. By default it shows only Apps modules. Since we created an application module we don't need to remove that filter to see it. Type "todo" in the search and you should see our new module, ready to be installed.

Now click on its Install button and you're done!

Upgrading a module


Developing a module is an iterative process, and you will want changes made on source files to be applied and visible in Odoo.

In most cases this is done by upgrading the module: look up the module in the Local Modules list and, since it is installed, you will see an Upgrade button available.

However, when the changes are only in Python code, the upgrade may not have an effect. Instead of a module upgrade, an application server restart is needed.

In some cases, if the module has changed both in data files and Python code, you might need both operations. This is a common source of confusion for newcomer Odoo developers.

But fortunately, there is a better way. The simplest and fastest way to make all our changes to a module effective is to stop (Ctrl + C) and restart the server process requesting our modules to be upgraded on our work database.

To start the server upgrading the todo_app module in the v8dev database, we will use:

$ ./odoo.py -d v8dev -u todo_app

The -u option...

Creating an application model


Now that Odoo knows about our new module, let's start by adding to it a simple model.

Models describe business objects, such as an opportunity, a sales order, or a partner (customer, supplier, and so on.). A model has a list of attributes and can also define its specific business.

Models are implemented using a Python class derived from an Odoo template class. They translate directly to database objects, and Odoo automatically takes care of that when installing or upgrading the module.

Some consider it good practice to keep the Python files for models inside a models subdirectory. For simplicity we won't be following that here, so let's create a todo_model.py file in the todo_app module main directory.

Add the following content to it:

# -*- coding: utf-8 -*-
from openerp import models, fields
class TodoTask(models.Model):
    _name = 'todo.task'
    name = fields.Char('Description', required=True)
    is_done = fields.Boolean('Done?')
    active = fields.Boolean...

Adding menu entries


Now that we have a model to store our data, let's make it available on the user interface.

All we need to do is to add a menu option to open the To-do Task model so that it can be used. This is done using an XML file. Just as in the case of models, some people consider it good practice to keep the view definitions inside a views subdirectory.

We will create a new todo_view.xml data file in the module's top directory, and it will declare a menu item and the action performed by it:

<?xml version="1.0"?>
<openerp>
  <data>

    <!-- Action to open To-do Task list -->
    <act_window id="action_todo_task"
      name="To-do Task"
      res_model="todo.task"
      view_mode="tree,form" />

    <!-- Menu item to open To-do Task list -->
    <menuitem id="menu_todo_task"
      name="To-Do Tasks"
      parent="mail.mail_feeds"
      sequence="20"
      action="action_todo_task" />

  </data>
</openerp>

The user interface, including...

Creating views – form, tree, and search


As we have seen, if no view is defined, Odoo will automatically generate basic views to get you going. But surely you would like to define the module views yourself, so that's what we'll do next.

Odoo supports several types of views, but the three main ones are: list (also called tree), form, and search views. We'll add an example of each to our module.

All views are stored in the database, in the ir.ui.view model. To add a view in a module, we declare a <record> element describing the view in an XML file that will be loaded into the database when the module is installed.

Creating a form view

Edit the XML we just created to add this <record> element just after the <data> opening tag at the top:

<record id="view_form_todo_task" model="ir.ui.view">
  <field name="name">To-do Task Form</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">

    <form string="To-do Task">...

Adding list and search views


When viewing a model in list mode, a <tree> view is used. Tree views are capable of displaying lines organized in hierarchies, but most of the time they are used to display plain lists.

We can add the following tree view definition to todo_view.xml:

<record id="view_tree_todo_task" model="ir.ui.view">
  <field name="name">To-do Task Tree</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">
    <tree colors="gray:is_done==True">
      <field name="name"/>
      <field name="is_done"/>
    </tree>
  </field>
</record>

We have defined a list with only two columns, name and is_done. We also added a nice touch: the lines for done tasks (is_done==True) are shown in grey.

At the top right of the list Odoo displays a search box. The default fields it searches for and available predefined filters can be defined by a <search> view.

As before, we will add this to the...

Left arrow icon Right arrow icon
Download code icon Download Code

Description

This book is intended for developers who need to quickly become productive with Odoo. You are expected to have experience developing business applications, as well as an understanding of MVC application design and knowledge of the Python programming language.

Who is this book for?

This book is intended for developers who need to quickly become productive with Odoo. You are expected to have experience developing business applications, as well as an understanding of MVC application design and knowledge of the Python programming language.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 06, 2015
Length: 214 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392796
Vendor :
Odoo S.A
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Apr 06, 2015
Length: 214 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392796
Vendor :
Odoo S.A
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 148.97
Odoo Development Cookbook
$54.99
Working with Odoo
$60.99
Odoo Development Essentials
$32.99
Total $ 148.97 Stars icon

Table of Contents

11 Chapters
1. Getting Started with Odoo Development Chevron down icon Chevron up icon
2. Building Your First Odoo Application Chevron down icon Chevron up icon
3. Inheritance – Extending Existing Applications Chevron down icon Chevron up icon
4. Data Serialization and Module Data Chevron down icon Chevron up icon
5. Models – Structuring the Application Data Chevron down icon Chevron up icon
6. Views – Designing the User Interface Chevron down icon Chevron up icon
7. ORM Application Logic – Supporting Business Processes Chevron down icon Chevron up icon
8. QWeb – Creating Kanban Views and Reports Chevron down icon Chevron up icon
9. External API – Integration with Other Systems Chevron down icon Chevron up icon
10. Deployment Checklist – Going Live Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(29 Ratings)
5 star 69%
4 star 24.1%
3 star 0%
2 star 6.9%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Javier Chacon May 19, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Daniel Reis really wrote a terrific book. This is one of the best books I've ever read about an application development environment completely new for me (as Odoo was some days ago). This book represented the guide I was looking for to learn about application development with Odoo.- The book conveys new key concepts in clear and direct way to be easily and quickly catched and applied even for completely new Odoo developers.- I was more than glad when realized that the book does not stop at just an introductory level of development in Odoo environment, but that it takes the reader to a higher level, boarding themes like for example application extension by using concepts like inheritance and other more elaborated topics, exposing them in very clear way too.This book follows Packt books great tradition of teaching by reading-doing-explaining-"and seing inmediate results" as part of the reader’s learning process.I got the book after its launching and I assure that the book’s worth its price.Thanks to Daniel Reis for such a great job!!!
Amazon Verified review Amazon
Marek Ilnicki Jun 13, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very useful book.
Amazon Verified review Amazon
Axon ehf. Jul 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Explains well how to develop for Odoo. Recommended.
Amazon Verified review Amazon
Narayana Moturi Apr 19, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
'Practical' and 'Professional' to describe this book. After buying every online course available on Odoo technical , I could confidently say this is the ONLY best book ( Odoo technical resource) I found so far written professionally, having excellent command on software architecture in general the author has made the reader to start with basics and transfer into more in-depth technical details. It is indeed an "Essential" book to have for every Odoo developer.
Amazon Verified review Amazon
Cliente Amazon Nov 13, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ottimo libro per chi è alle prime armi su odoo, utile per iniziare a sviluppare i propri moduli.Inutile se avete intenzione di capire come configurare una piattaforma odoo compelta.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.