Archive for the ‘Python’ Category

How to debug your OpenERP modules

Debugging your OpenERP modules is quite straightforward, as long as you know basic Python programming. Just insert the following line in your

English: Python logo Deutsch: Python Logo

Image via Wikipedia


import pdb;pdb.set_trace()

Then restart your openerp-server with the —debug option

# openerp-server –debug

Then monitor your server console. You will see your server stop and show you a command line prompt where you will be able to debug your program.
You will find further information in the Python documentation website.

ABC Analysis in OpenERP

December 26, 2011 Leave a comment

ABC analysis is very well covered in this Wikipedia article. So no point of talking about it again here. Thing is, how do you implement it in OpenERP.

Polish OpenERP screenshot

Image via Wikipedia

Truth is, it is not a great deal. You only need to pull the sale order lines for the past six months (for example, could be a year as well or the period under analysis), then by product summarize its sales (not taking into account any discounts) and then divide the sales number by the total sales amount, in order to figure out the product ABC Category. If you are an experienced programmer or data analyst, you can do this in minutes. If not, does not take long to figure out how to query the OpenERP database.

Thing is, this information is not integrated into OpenERP yet (and it makes sense, since you do not need this information for the MRP application. It’s nice to have it, but it is not critical). So I created a module that regularly categorizes OpenERP products according to its sales. I have not finished it yet and I need to upload it to LaunchPad, but I think I will do it this week.

What does this module do? Allows you to create ABC categories (you can have as many as you want) where you define the category and its range. Then regularly (as an scheduler action) categorizes the products taking into account their sales lines. Then updates the product abc_category field (created previously by the module installer).

I still need to polish the module and add a couple of files, such as a XML file with initial information (specially for the scheduler and categories). As soon as I get it done, I will upload it to LaunchPad and publish it.


OERPEnv: an environment manager for OpenERP

My business partner Cristian developed last week an application for managing different independent development/production environments in OpenERP. The idea is the tools allows you develop new modules easily, test new ones and test different configurations. For those with experience in Drupal, OERPEnv is similar to the drush tool. These days this tool is under development, so we don’t recommend it for those without Linux experience.

Below is the repository link where you can download the tool:

If you have any question, please feel free to ask.


Categories: Configuration, Python, Ubuntu

Python for Fun, a cool website for practicing Python

I just found this nice website, aimed at the intermediate Python programmer. Contains small Python programs, which will expand our Python knowledge. Hope you enjoy it as much as I do!

Categories: Python, Reads, Uncategorized

Importing products with web-services in OpenERP

Python logo

Image via Wikipedia

Yesterday someone at the OpenERP forum asked me for an example of how to import product data into OpenERP, so here it is, below you will find an example of a Python script for loading basic product data.

#!/usr/bin/env python
# coding: utf-8

import xmlrpclib
import csv

username = ‘admin’ #the user
pwd = ‘pwd_admin’ #the password of the user
dbname = ‘blog_db’ #the database

# Get the uid
sock_common = xmlrpclib.ServerProxy (‘http://localhost:8069/xmlrpc/common’)
uid = sock_common.login(dbname, username, pwd)

#replace localhost with the address of the server
sock = xmlrpclib.ServerProxy(‘http://localhost:8069/xmlrpc/object’)

#load categories first
filename = “categories.csv”
reader = csv.reader(open(filename,”rb”))
for row in reader:
category = {
‘name’: row[1],
‘active’: True,
category_id = sock.execute(dbname, uid, pwd, ‘res.partner.category’, ‘create’, category)
print category_id

print “End categories load”

filename = “product_template.csv”
reader = csv.reader(open(filename,”rb”))
for row in reader:
product_template = {
‘name’: row[0].rstrip(),
template_id = sock.execute(dbname, uid, pwd, ‘product.template’, ‘create’, product_template)
print template_id

product_product = {
‘default_code’: row[0].rstrip(),
‘active’: True,
product_id = sock.execute(dbname,uid,pwd,’product.product’,’create’,product_product)
print product_product

print “End product load”

This is a simple script you can execute from the command line. In summary, first you need to create the categories and then you need to create the product.template objects and product.product objects. If you have any question about this, please let me know.


openerp-server 5.0 and Python 2.7

Ubuntu Inside

Image by Kordite via Flickr

After upgrading Ubuntu to 11.04 I found the nasty surprise that openerpserver 5.0 could not create a new database because it threw the following error message:

ValueError: opcode JUMP_IF_FALSE_OR_POP not allowed (u’auto_picking and test_auto_picking()’)

After doing some quick research with Google, I found the following bug that is already fixed in openerp-server v6:

Since upgrading to openerp v6 at this time is not an option for me, I only needed to make a slight change to make openerp-server work with Python 2.6. I already had python 2.6 installed in my Ubuntu system, which I could check with the following command:

gustavo@gustavo-laptop:/usr/bin$ python2.6
Python 2.6.6 (r266:84292, Mar 25 2011, 19:36:32)
[GCC 4.5.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

Then I changed the openerp-server command at my /usr/local/bin directory. I only needed to change the

exec /usr/bin/python ./ $@

line to

exec /usr/bin/python2.6 ./ $@

And that is all I needed to do to get my system back to work


HR Attendance analysis with OpenERP

March 27, 2011 2 comments
KDE 4.0

Image via Wikipedia

My partner, Cristian Sebastian Rocha, has been working the past three months in the development of the hr_attendance_analysis module, which, as its name suggests, helps companies analyze their employees attendance.

This module allows you make calculations on the worked hours by employees. You can apply formulas and calculation rules in order to automate attendance calculation. It can also be integrated with other HR related modules, such as the clock_reader module.

This module also has a workflow for confirming the entered date on each document type, journal and payroll. The first document holds daily attendance information for the employee, whereas payroll holds payroll information on a monthly, bi-weekly or daily basis.

These are some screenshots for the module:

In this image you can see the main menu for accessing the HR module. You can also see the menu items for accessing the Payroll documents (selected) and Attendance Journals.

In this image you can see the document with the summary of employee hours (filtered by a date range). You can leave notes for each employee or for the document. It can have two states: draft and validated. We still have to develop the workflow for cancelling and re-setting the document.

In this screenshot we can see the entry for the employee Journal. Here you can see in detail the in and out time for a given date. You can also see the vacations or time off hours (such as late arrivals, early departures, sick days, etc.) To the left you can also see the result of the hours calculation.

This is a formula for summarizing the values stored in the journal, in order to be shown in the Payroll document.

This is a formula for calculating normal hours in a givenĀ  date for a given employee:

In this screenshot, you can see a rule. This rule assigns reasons for the actions of entering or leaving the plant. IN this case we can see how to calculate an early leave without a warning.

We still have things to do, but soon we will upload the module to LaunchPad. If you have any comments, or suggestions, they are more than welcome.