Posts Tagged ‘Languages’

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.


Managing your openerp processes with Supervisor

Reading a book on system administration with Python I found Supervisor, which is a tool that allows you manage your programs. I found it easy to

English: A picture of a Dell PowerEdge 850 web...

Image via Wikipedia

install and learn, and in minutes I had it running in my system. After reading the documentation, which took me minutes, I was able to configure its configuration file, restart the daemon and have openerpserver and openerp-web running automatically in my computer.

Below is am example of how to modify the supervisord.conf file in order to start openerp-server and openerp-web



Why I like it? Because this tool allows me to manage my process and it does not take me long to do that. It can also be controlled by other Python programs, which might be handy in some projects.


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.


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


Thoughts on why some SMBs will switch to OpenERP over traditional ERP systems

Python logo

Image via Wikipedia

Today I had the chance to learn about the features of a propietary ERP system. This gave me a good  insight of why small businesses are moving to OpenERP. Some of the features customers appreciate are:

  • Customers can customize OpenERP. I did not realize it, but there are many systems around that are closed and can not be modified. And making changes to it means making changes to its core. And this could take months. This is the opposite of OpenERP, just look at OpenObject and you can see how easy it is to extend or override its functionality. Also, workflow functionality is quite powerful. Not all ERPs have the capability of changing its behaviour as OpenERP does.
  • Customers can look at the code. This might sound paranoid, but gives them confidence on the system.
  • No vendor lock-in. Customers love this. The fact they don’t have to stop the plant in order to switch vendors is highly appreciated. And being capable of keeping the code and giving its customization to someone else who is capable of maintaining it, makes life easier for our clients.
  • Support forums
  • Have I mentioned Python? OK, not all the IT people I know have ever heard of Python, but the people I met today were running their ERP system with Centura, which is a framework based on SQLWindows, one of the first object oriented programming languages in the mid-90s. With this I mean… OpenERP runs with one of the most productive programming languages in the world. Plus, even though we are not millions, the group of people working with Python is growing every day.
  • TCO. This is a big deal. Not only the licenses (all the ERP systems I see over here have licenses that are more expensive than $40,000) but the hardware and software as well. You only need a browser on your desktop to use OpenERP, no Windows licenses. And no server license as well. This saves thousands and thousands of dollars.
  • And last but not least, the web client. This makes the life of the system administrator much easier


Python Entre Todos – A new online Python magazine (in english, of course)

February 20, 2011 Leave a comment
Python logo

Image via Wikipedia

PET, or Python Entre Todos (which means “Python among us” in spanish) is a new Python online magazine. It is written by argentinian Python developers in spanish and english. You can find the english issue here:

Python Entre Todos – English Translation – Issue #1

The goal of the magazine is to spread Python as a programming language in the community.

Why I read it? here are some of my reasons:

  • even though you don’t need Python to implement OpenERP, the more you know about this programming language the better. And reading a Python magazine is a good way to improve my OpenERP skills
  • I miss Python Magazine
  • I do not find good printed technical magazines, so I have to fall into online magazines. And I think PET will become one of my favorites soon
  • the more knowledgeable in Python the OpenERP is, the better. We will have better modules, and OpenERP will be more modular. Which will increase its adoption

So far there is one issue online, but two more issues are on the way.

Have a great Sunday!