Field of type Reference in Odoo, how to use it ?

Reference field type in Odoo

The main use of this field type is to make a reference with a specific model and then a specific recordset of this model.

By using the reference field type, the first thing you will choose is the model:

field reference

And by choosing the model you will be asked the choose one of the recordset of the chosen Model

field reference recordset

Structure of the reference field in Odoo (New API)

A field of type reference is declared as below :

ref = fields.Reference(string='Reference', selection='_get_document_types')

Selection attribute : We define the method that will determine which models will be showed, and from which we can choose

In our example we used this method :

method selection field reference

    def _get_document_types(self):
        records = self.env['ir.model'].search(['|', ('model', '=', 'sale.order'), '|', ('model', '=', 'account.invoice'), '|', ('model', '=', 'stock.picking'), ('model', '=', 'purchase.order')])
        return [(record.model, for record in records] + [('', '')]

In this example, we specified that we want to choose from [ Sale Order, Account Invoice, Stock Picking, Purchase Order ] models

Hope it was useful for you
Good luck !!

Odoo : SQL Query Tips

In this article we will show some useful tips that will help you work with SQL Queries in python/Odoo.

How to execute queries in Odoo 10 ?

you should use the to run a sql query

cr =
cr.execute("SELECT a, b, c FROM [your_table] WHERE [condition]")

It’s highly recommended to use the double quotes ” ” instead of single quotes ‘ ‘

What’s the query can returns ?

cr.dictfetchall() : will give you all the matching records in the form of the list of dictionary containing key, value [{'': ''}, {'': ''}, ...].
cr.dictfetchone : works same as cr.dictfetchall() except it returns only a single record {'': ''}.
cr.fetchall() : will give you all the matching records in the form of the list of tuple [(''), (''), ...].
cr.fetchone() : works same way as cr.fetchall() except it returns only single record ('').

SQL Queries with variables

You can execute Queries with variables using %s like:

cr.execute("SELECT a, b, c FROM [your_table] AS a WHERE = %s AND a.field = %s", (first_value, second_value))

Hope it was useful for you
Good luck !!

List Vs Tuple in python with Odoo

Hello everyone

In this article we will emphasize the difference in the use of tuple and list :

list gives you values between brackets “[]”. For example, when we do in odoo:

account_ids = self.env['account.account'].search([])
account_ids ---> [1, 4, 5, 8 , 9]

account_ids is a list of values

We can use this list:

* in loops:

for account_id in account_ids:
     move = self.env['account.account'].search([('account_id', '=', account_id)])

* to search in another table:

move = self.env['account.account'].search([('account_id', 'in', account_ids)])

* to change or search a specific value:

account_ids[2] -----> 5
account_ids[4] -----> 9
account_ids[0] = 10 -----> will replace the first value "1" by "10"

* change a tuple to a list:


tuple gives you values between parentheses “()”. we can use them in :

* change a tuple to a list:

account_ids = tuple(self.env['account.account'].search([])) 
account_ids ---> (1, 4, 5, 8 , 9)

* in loops:

for account_id in account_ids:
     move = self.env['account.account'].search([('account_id', '=', account_id)])

* to search in another table:

move = self.env['account.account'].search([('account_id', 'in', account_ids)])

* in SQL filter Query:

In SQL Query we should use a tuple of values and not a list

account_ids = tuple(self.env['account.account'].search([]))
cr.execute('SELECT * FROM account_move_line where account_id in %s,(account_ids))

what is Odoo ?

Hello everyone

Today’s article will be about “what is Odoo ?”, so you’ll get the chance to discover Odoo: its definition and its release history.

Overview about Odoo:

Odoo, formerly known as OpenERP, is a suite of enterprise management applications. Targeting companies of all sizes.

The application suite cover all the company’s needs:  CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

It is 100 % modular application, so when Odoo is first installed there are ZERO modules installed with it, so you are able to only install the modules you need.

Odoo includes the following modules that may be installed with a simple mouse click:

– Accounting
– Customer Relationship Management (CRM)
– Warehouse Management
– Manufacturing Resource Planning (MRP)
– Purchase Management
– Project/Service Management
– Human Resource Management (HRM)
– Content Management (CMS)
– Document Management
– Fleet Management
– Point of Sale (POS)
– Application Builder


  • Odoo offers a simple and rapid solution for all users, it allows you to customize or modify your modules.
  • Odoo is writing in Python, JavaScript and XML.
  • Odoo is compatible with: Linux, Unix-Like, OS X and Windows

Release history:


NB: Odoo have released software as open source but starting at the V9.0 release, the company of Odoo has transitioned to an open core model which provides subscription-based proprietary Enterprise software and cloud-hosted Software as a service, and a cut-down community version.

Software license:

  • GNU General Public License (GNU GPL):  is a widely used free software license, which guarantees end users the freedom to run, study, share and modify the software.
  • GNU Affero General Public License ( GNU AGPL): is a free, copyleft license published by the Free Software Foundation in November 2007, and based on the GNU General Public License, version 3 and the Affero General Public License.

The Free Software Foundation has recommended that the GNU AGPLv3 be considered for any software that will commonly be run over a network.

  • GNU Lesser General Public License (GNU LGPL): is a free software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate software released under the LGPL into their own (even proprietary) software without being required by the terms of a strong copyleft license to release the source code of their own components.

Debug Odoo 10.0 using Pycharm in Windows

Hello everyone
This article well help you step by step to debug odoo-10.0 in Windows using PycharmProjects.

For the environment, I am using Windows 7 and Pycharm, version 2016.3 in 64 bit

This article is divided into three parts:
Part 1: describes how to install required packages and source code
Part 2: show how to configure PostgresSQL and Odoo
Part 3: gives you the solution of some errors occurred while my installation process


I.Install required packages and source code:

1.1-Install Pycharm:

1.2-Install Python 2.7:

1.3-Install odoo 10:

First, go to: 

to download the field “”, after that extract the content of “”.

1.4- Run Pycharm, and open the odoo-10 ( folder extracted earlier )



1.5-Install Microsoft Visual C++ Compiler for Python 2.7 if you don’t have one:

1.6-Install required packages:

For this step you could either:

Install the requirements.txt once you open PycharmProjects, it will appear a message asking you to install “requirements.txt

Go to “cmd” command line and execute these commands:

> cd C:\ python27 (here you specify the location of your field “python27”)
> python -m pip install -r C:\Users\PycharmProjects\Odoo-10.0\requirements.txt  (here you specify the location of your field “Odoo-10.0”)

NB: some of this required packages will not be installed, to do so I ask you to refer to the part 3 of this article.

1.7-Install pywin32 (This installation is optional) :

While installing the required packages missing, you may have some errors dealing with pywin32. So all you need to do is to install it:

link to the pywin32.exe

1.8-Install pip:

-Go to:


-Go to “cmd” command line and execute these commands:

> cd C:\python27(here you specify the location of your folder “python27”)
> Python

II.Install PostgreSQL and configure Odoo:

2.1- install and download PostgresSQL for Windows:

Download PostgreSQL from official website

NB : You should remember the password of “postgres” role that you set when installing will need it in the next step.

2.2- Create a new role with superuser privilege for Odoo application:

In my case, I create a superuser “lenovo” and set its password as “lenovo”.
To do so, Go to “cmd” command line and execute these commands:

> cd "C:\Program Files\PostgreSQL\9.4\bin"
> createuser.exe --createdb --username postgres --no-createrole --pwprompt lenovo

2.3- configure Odoo:

To configure Odoo, you can refer to the file odoo-server.conf:

This is the password that allows database operations:

; admin_passwd = admin
db_host = localhost
db_port = 5432
db_user = lenovo
db_password =lenovo
addons_path = C:\Users\PycharmProjects\odoo10\addons

If you want to change your port, you can add this line to that file: xmlrpc_port = 8070

III.Errors and solutions:

3.1-You may have an error telling that you don’t have “Setuptools”, so you can install it.

To do so, go to “cmd” command line and execute these commands:

> cd C:\python27
> python -m pip install --upgrade setuptools

3.2- Install wheel & lxml-3.6.4-cp27-cp27m-win32.whl:

Go to “cmd” command line and execute these commands:

> cd C:\python27
> python -m pip install wheel

To install lxml-3.6.4-cp27-cp27m-win32.whl, go here

Then, go to “cmd” command line and execute this commands:

> cd C:\python27
> python -m pip install lxml-3.6.4-cp27-cp27m-win32.wh

(here you should choose the file that go with your environment)

3.3- Install ebaysdk:

Go to:

(here you should choose the file that go with your environment)

Then, go to “cmd” command line and execute these commands:

> cd C:\python27
> python -m pip install "C:\path to\tar\ofxparse-0.15.tar.gz "

3.4- Install psycopg2 .exe:

3.5- once you launch your odoo server using your navigator: localhost: 8069, you may have this error: « could not execute command lessc »

to resolve that problem, you follow those steps:

  • – Install nodejs :
  • – go to “cmd” command line and execute this commands:
> cd C:\Program Files\nodejs (here you specify the location of your field “nosejs”) 
> npm install -g less less-plugin-clean-css

3.6- how to use wkhtmltopdf to print a PDF:

  • -Install wkhtmltopdf :  (Windows (MSVC 2013))
  • -In system variable on windows add in PATH: C:\Program Files\wkhtmltopdf\bin
  • -Restart the OS(systeme windows)

Debug Odoo 9 & 8 using Eclipse IDE

Hello everyone
We will show you in this tutorial, how to debug Odoo V9 / V8 from Eclipse IDE ( step by step ). We will be working on Ubuntu  14.04 for stability reasons, but you can use any other version.

Update the system and install necessary packages for Odoo :

First thing to do is to update your system, which let you get the newest versions of packages and their dependencies existing on your machine.

#sudo apt-get update
#sudo apt-get upgrade

aptget upgrade

aptget update

Then we should install the Prerequisites packages for Odoo :

#sudo apt-get install python-cups python-dateutil python-decorator python-docutils python-feedparser python-gdata python-geoip python-gevent python-imaging python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-passlib python-psutil python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests python-simplejson python-tz python-unicodecsv python-unittest2 python-vatnumber python-vobject python-werkzeug python-xlwt python-yaml wkhtmltopdf

To install wkhtmltopdf (a package that let you print reports in Odoo 8 & 9), you should run this commands :

#sudo wget
#sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb
#sudo cp /usr/local/bin/wkhtmltopdf /usr/bin
#sudo cp /usr/local/bin/wkhtmltoimage /usr/bin

For Ubuntu 14.04 users, you should install “python-passlib” package, to avoid “error 500 Internal Server” Error :

#sudo apt-get install python-passlib

Setup Eclipse :

Very Important : For me I used LiClipse is a very featured Eclipse (Provides a number of enhancements) for Linux with PyDev (Python) support, To install/run it : (A big thanks to arulmr)

LiClipse is the lightweight version of the most popular Eclipse IDE and it includes PyDev and Egit by default which will help python/django developers

To install it follow my article Liclipse (Eclipse) Installation on Ubuntu

Once LiClipse installation is Done. We need to setup the GIT repository in order to download Odoo Source code. To do so, Click Windows -> Open Perspective -> Other

Eclipse 7

A Window will Open ask you to select a perspective. Click Git

Eclipse 8


In Next Windows Select “Clone a Git Repository

Eclipse 9

In th URI field type ““ | In the Host field type ““ | In the Repository path type “/odoo/odoo.git“. Click Next

Eclipse 10

You will be presented which Branches you want to clone, You can see all of the versions of Odoo. Select only 8.0 or 9.0 or which ever version you want.

In next windows Select the Directory where you want to clone the Source and Click Finish (We recommend Eclipse workspace  : /home/workspace/odoo). The Cloning Process will begin. This Process may Take a while depending on the speed of your Internet.

Now we need to Setup eclipse’s Perspective to work with Python. To do so click Window -> Open Perspective -> Other and from the Window Select Pydev and Click OK.

Eclipse 11

To setup the Interpreter for python, Click Windows -> Preference and In the Left Pane, Select Pydev and the Interpreter Python and then Click Auto-Config on the Right side, The System will automatically detect Your python version. Click OK to Close this Windows once eclipse is done setting up Environment.

Eclipse 13

To dispaly your code in Eclipse Click File -> Pydev Project.

In project name type odoo the name you like. uncheck Use Default and click Browse and select the source directory (The directory that you specified earlier, where cloning the source. As an example we used /home/workspace/odoo ) and click Finish.

We Finished with setting up Eclipse for Odoo use.

Setting up Odoo Configuration File

You can create your own config file for Odoo like this one :

#sudo nano /etc/openerp-server.conf

Copy this content in the file :

; This is the password that allows database operations:
; admin_passwd = admin
db_host = False
db_port = False
db_user = odoo
db_password = False
addons_path = /home/workspace/odoo/addons

( In addons_path you should use your own addons directory )

ctrl + o to save the file and ctrl + x to exit nano

To take this file in consideration go to the “Running the Code of Odoo from Eclipse” step.

Configure PostgreSQL server

Now we need to create a role in PostgreSql for the user that will be Running Eclipse.

Usually we use our current user

#sudo su postgres
#psql -t template1
#template1=# create user usmanbek with superuser password 'postgres';
#template1=# \q

Running the Code of Odoo from Eclipse

To take the openerp-server.conf file in consideration, you should go to Eclipse openerp-server -> Run As -> Run Configuration.

config 1

In the argument tab click on Variables.

config 2

A select variable box appears. Click on Edit Variables.

config 3

A preferences box appears. Click on New.


A new box appears. Put whatever you want in “Name” field, Ex: Config file | In the “Value” field put : –config=/etc/openerp-server.conf


Choose the variable you have just created (for my case it’s Config file) and Click Ok

config 6

Finally you click on Run 🙂

Now to access the Webclient, type localhost:8069. You will see this page.

odoo running

Congratulation, now you can develop Odoo modules easily