Customizing existing modules in OpenERP 7.0

Getting started on OpenERP can be a bit difficult, but when you get familiar with OpenERP API, you will be able to develop any new feature easily. Following this post, you’ll learn how to customize existing modules by adding new fields and extending existing views.

First of all, you should have a development environment. If you didn’t have one, you can check out this tutorial here. Once the database is created, go to Settings > Modules > Apps, and install the Timesheets application.

When the installation is finished, click on the Human Ressource menu, then on Timesheet activities view and click on create button, you will get the below view.

Default Timesheet Activities Tree View

We will go throught steps involved to obtain the below view:

expected_timesheet_activities_view

1. Create hr_timesheet_performance module

A basic module, is a python package containning an __openerp__.py file which declare the module definition. In our case, put inside it the following:

# -*- coding: utf-8 -*-
{
    'name': "Timesheet Performance",
    'version': "0.1",
    'author': "Wael BEN ZID",
    'category': "Tools",
    'depends': ['hr_timesheet_sheet'],
    'data': [],
    'demo': [],
    'installable': True
}

2. Update module list

Now go to Settings > Update module list and click on Update button, this will refresh the system module cache. If you didn’t see the Update module list sub-menu, this is because you have not Technical features permission. So go to Settings > Users and edit your account. Enable the Technical features check-box under usability. Finally, refresh your browser.

enable_technical_features

3. Install module

Now, go to Settings > Modules > Apps, search for Timesheet Improvement module and install it.

4. Extends the OpenObject model

Now lets extends the model by adding new fields. So create a hr_timesheet_performance.py file and put the following:

# -*- coding: utf-8 -*-

from openerp.osv import fields, osv

class hr_analytic_timesheet_performance(osv.Model):
    _inherit = "hr.analytic.timesheet"

    _columns = {
        "hour_start": fields.float("De"),
        "hour_end": fields.float("Au")
    }

    _defaults = {
        "hour_start": 8,
        "hour_end": 9
    }

hr_analytic_timesheet_performance()

In the first line, we import the required classes, then we will create our class which will extends the hr.analytic.timesheet model, by telling OpenObject that our class will inherits from it

_inherit = "hr.analytic.timesheet"

This is the real magic in OpenObject ORM, then we will define new fields on _columns attribute. Finally, I defined some default values for the new field in the _defaults attribute. I set hour_start to 8 (you will see 08:00 in the interface), and hour_end to 9.

Now, we should tell OpenERP to load the new model definition, so add the below line in hr_timesheet_performance/__init__.py

import hr_timesheet_performance

5. Extends the default view

Now, lets update the UI (OpenERP view), So, create a new file called hr_timesheet_performance_view.xml and put the following:


<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record model="ir.ui.view" id="pv_performance_timesheet">
  <field name="name">hr.analytic.timesheet.performance.tree</field>
  <field name="model">hr.analytic.timesheet</field>
  <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
  <field name="arch" type="xml">
    <field name="account_id" position="after">
      <field name="hour_start" widget="float_time" />
      <field name="hour_end" widget="float_time" />
    </field>
  </field>
</record>

</openerp>
</data>

I defined a view called hr.analytic.timesheet.performance.tree which will use hr.analytic.timesheet as a model and inherits from the default view:

<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />

In this view, we will add hour_start and hour_end fields and use a float_time widget for both of them after the field account_id

<field name="account_id" position="after">
    <field name="hour_start" widget="float_time" />
    <field name="hour_end" widget="float_time" />
</field>

We should now tell OpenERP to load this view when it try to install/upgrade the module, So update data list in __openerp__.py file:

'data': ["hr_timesheet_performance_view.xml"],

So we will obtain the final module descriptor below:

# -*- coding: utf-8 -*-
{
    'name': "Timesheet Performance",
    'version': "0.1",
    'author': "Wael BEN ZID",
    'category': "Tools",
    'depends': ['hr_timesheet_sheet'],
    'data': ["hr_timesheet_performance_view.xml"],
    'demo': [],
    'installable': True
}

6. Upgrade module

Now, go to Settings > Apps> Installed Modules, select Timesheet Improvement module and upgrade it.

Once it’s done, go to the Timesheet Activities view, and you’ll see something like that:

new_timesheet_activities_view

 

What’s next ?

Now, I think that you found that development in OpenERP is not difficult. I hope that this tutorial has been helpful. In the next post, I’ll show you how to implement buisness logic.

Multi-address in OpenERP V7.0

OpeneRPP manage natively multiple addresses for each partner. Remind a partner in openerp, includes both a client a supplier. In version 7.0, this option is not active by défaut, you will certainly need to manage multiple addresses for your partners. Indeed, it is very common to charge a client an address and send the bill to a second address. To activate it:

  1. proceed to the Configuration section
  2. In the left sidebar, under the subpart Configuration choose sales
  3. Then check “Allow a different address for delivery and invoicing” checkbox

adresse-openerp

Good bye Bazaar and Launchpad !

The transition from OpenERP to Odoo comes with an excellent new technique:

Get rid of BZR!

The really good news is the abandonment of Bazaar and Launchpad, which were a serious handicap. The merger of the three bazaar branches into only 1 Git repository should be able to speed up things and facilitate the contribution. Even if the contribution process is not yet well defined on github,  but it would be highly desirable if it will be organized around a merges’s rise model, like the Linux kernel.

Saving time and disk space

Clone a repository from github takes a lot less time than recovering a bazaar branch on Launchpad. In addition to time savings, it also save disk space. Here is a comparison of the sizes of deposits:
OpenERP in BZR
openobject-server 154 Mo
openobject-addons 692 Mo
openerp-web 33 Mo
Odoo (Github)
Odoo 432 Mo
The only thing that we lose with git is the notion of shared repository of Bzr.