Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to Debug python code in open erp

on 8/14/13, 4:09 AM 27,897 views

I want to debug my python code in open erp i had given print statement but its not showing in log I check in tail -f /var/log/openerp/openerp-server.log any one please help?


Thierry Godin

--Thierry Godin--
| 8 7 8
Collegien, France
--Thierry Godin--


Thierry Godin
On 8/14/13, 4:58 AM


I use this for debugging :

import logging
_logger = logging.getLogger(__name__)

class my_class(osv.osv):

    # in the code when needed :
    _logger.error("my variable : %r", my_var)

    # Or
    msg = "This is my error message : " % my_var

and in the log file , I'll have a line containing : my variable: + value of my_var

or : This is my error message + value of my_var

Of course, debug must be enabled in openerp-server.conf

Best regards

i enabled debug mode by setting debug_mode = true in /etc/openerp/openerp-server.conf and checking log tail -f /var/log/openerp/openerp-server.log but still its not showing print

on 8/14/13, 5:04 AM
import logging
from openerp.osv import fields, osv
import time
import pdb

_logger = logging.getLogger(__name__)
class calldata_print_report_wiz(osv.osv_memory):
    _name = "calldata.print.report.wiz"

    def _sel_func(self, cr, uid, context=None):

     print "hello"*100
     obj = self.pool.get('calldata1')
     ids = obj.search(cr, uid, [])
     res = obj.read(cr, uid, ids, ['Caller'], context)
     res = [r['Caller'] for r in res]
     return res
on 8/14/13, 5:30 AM

Leonardo Donelli

--Leonardo Donelli--
| 5 4 8
Cave, Italy
--Leonardo Donelli--

Physics student and part-time developer.

Leonardo Donelli
On 6/19/14, 9:01 AM

A non IDE-specific way to debug Python code is to import the pdb module (Python Debugger) and call pdb.set_trace() in your code where you want the debugger to open, it basically sets a breakpoint. Once in the debugger you can do a lot of things, like printing variables values, moving in the call stack, etc. see the pdb module documentation.

Thanks I like it!

Pascal Tremblay
on 12/12/14, 11:46 AM

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 6/18/14, 5:44 AM

Follow the given steps to debug your python code in eclipse:

1) Go to '/openerp/server/openerp-server' and select openerp-server file, then right click on that file and select Debug As -> Python Run which will start the server.

2) After creating new debug configuration Go to 'Run -> Debug Configuration' and follow the given steps: 

    2.1: In "Arguments" tab under "Program Arguments", click on button "Variables" and new window will appear. 

    2.2: Then create new "Variable" by clicking on "Edit Variables" button and new window will appear.

    2.3: Press on "New" button and give your addons path as value. Ex: --addons ../addons,../your_module_path

     2.4: Press Ok in all the opened windows and then "Apply".

3) Now into "PyDev Package Explorer" view go to 6.1/server and right click on "openerp-server" file, Select 'Debug As --> Python Run'.

4) Now in "Console" you can see your server has been started.

5) Now open your .py file which you want to debug and set a breakpoint.

6) Now start your module's form from 'gtk' or 'web-client' and execution will stop when execution will reach to breakpoint.

7) Now debug your code by pressing "F5, F6, F7" and you can see value of your variables.

Thanks & regards,

Serpent Consulting Services Pvt. Ltd.



| 6 5 7
Tbilisi, Georgia
On 5/4/15, 8:30 AM

There is several ways to debug and I see you've got some good tips on the topic, but I'll narrow down your question to get worked print statement in python code as it's what you've tried, maybe it's your preferred way...

Instead of redirecting logs to logfile (to the /var/log/openerp/openerp-server.log in your case) and then read them from there using "tail -f" you can simply run openerp server from command line and you'll get printed stuff (including simple "print" command in python code) directly in the terminal from where you'll run the server. If you've installed nightly version and/or you're running openerp server in daemon mode, then you've to shutdown your server instance first ( something like: "/etc/init.d/openerp stop" or whatever is correct for your case). Then start the server from the terminal (you've to figure out what's path to the openep startup script, the odoo.py for v8 or openerp.py/openerp-server.py for v7), using command line options, at least use "--config=/path/to/your/config/file" option for reuse your config file. lets say server path is /usr/bin/openerp-server and config file is: /etc/openerp/openerp-server.conf, then you'll run it as "/usr/bin/openerp-server --config=/etc/openerp/openerp-server.conf" ( here you can use other options as well, including  --logfile=/var/log/openerp/openerp-server.log if you like) from terminal. Then in your python code you can

print "whatever" 

and you'll get whatever printed to the terminal.

Alejandro Perez Cosio
On 11/12/14, 5:48 PM

You can try with ipdb, it's a python debugger available from pip. 

​pip install ipdb

To use it, just import it somewhere on your code, set the trace and use your module (you should be running odoo NOT as a service)

# python code ...
import ipdb; ipdb.set_trace()
# python code ...

Start your server

<openerp_path>$ ./openerp-server

When the line with ipdb is executed, you will notice your process stops, and your terminal is ready to debug.
Some keywords:

  • c (continue): will quit from debugging mode and continue with the execution
  • n (next): will do a step forward on your debugged code

Hope it helps you!



Oleg Orlov
On 9/3/13, 1:21 PM

Simple howto debugging openerp7 with intellij idea on windows.


  • installed IntelliJ Idea 12 (www.jetbrains.com/idea/download/)
  • installed Openerp7 openerp-allinone-setup-7.0-latest.exe (www.openerp.com/start?download)

Step by step:

  • install intellij python plugin file->settings->plugins->install jetbrains plugins->python->install
  • download and install python 2.6 (i prefere portable version) portablepython.com/wiki/PortablePython1.1Py2.6.1/
  • copy listed files from portable python (F:\PortableApps\PortablePython_1.1_py2.6.1\App) to openerp (F:\OpenERP 7.0-20130731-231106\Server\server): python.exe Lib\site.py Lib\Queue.py Lib\trace.py
  • create new python project (openerp7debug) and configure python sdk file->new project->python module->openerp7debug->next->Python Interpreter->Configure-> + ->Python SDK->local->F:\OpenERP 7.0-20130731-231106\Server\server\python.exe->next->finish
  • right click openerp7debug->new->python file->openerp-server.py->add content

    import openerp if __name__ == "__main__": openerp.cli.main()

  • create debug configuration Edit configuration...-> + -> Python->Name: Debug openerp7->Script: F:\Users\orlov\YandexDisk\Work\openerp7debug\openerp-server.py-> Script parameters: "--config=F:\OpenERP 7.0-20130731-231106\Server\server\openerp-server.conf"-> Working directory: F:\OpenERP 7.0-20130731-231106\Server\server->OK

  • add breakpoint (on line openerp.cli.main() for example) and click debug, test breakpoints, inspect vars, test UI from browser
  • Happy debugging!
On 1/28/16, 4:43 AM

I have solved remote debugging to my remote ubuntu server by doing the following:

On your remote server, run: pip install cython pydevd

IMPORTANT: Make sure that your computer is visible to server's IP by pinging your computer's IP

On your computer, configure a Python Remote Debug in run configurations.

Set Local Host Name: The IP of your computer. Yes, that computer with the pycharm installed.

Set the Port: 7999. Actually, any port will do as long as its above 1000.

Make sure to check the box, SINGLE INSTANCE ONLY

On File>Settings>Execution>Deployment, create an SFTP Server Connection.

Set the SFTP host to the server's IP. set the root path to the installation directory of your odoo server. In my case, its located at /opt/odoo

Set the username and password.

On the mappings tab,

Set the Local Path to your project's directory root

Set the deployment path to "\" or backslash.

Set the web path to "/" or forwardslash.

Test the SFTP connection.

On the server, open the file /opt/odoo/openerp-server (It's a python file without the extension)

Add these statements after the "import openerp"

import pydevd

pydevd.settrace('YOUR COMPUTER IP', port=7999, stdoutToServer=True,stderrToServer=True)

TODO EVERYTIME YOU MODIFY YOUR CODE AND DEBUG THATNow to start the debug, add a breakpoint in your code.

Run the remote debug to start listening from the server.

Restart the openerp instance you got running in your server. In my case, I force restart the init.d/odoo-server file:

/etc/init.d/odoo-server restart

If successful, pycharm will light up in the menu bar and ask you to set the path mappings. Just click the autodetect and press Save forever.

Notice that if you visit the odoo server website, it just won't load. Actually, pycharm sets a "virtual" breakpoint after the settrace command you have provided so you have to press the play button thing at the debug(or F8)

Viola! Now it works and any breakpoint you set will stop odoo from executing and let you analyze everything.

Test it by adding a breakpoint in your code and try to run that code. Try the @api.onchange ones since they are more predictable to run.

eoin ahern
On 3/8/14, 11:26 AM

doesnt seem to be a Lib/Queue.py file in python 2.7 ??

oh, actually i found it so it is there!! my mistake

eoin ahern
on 3/8/14, 11:43 AM
On 8/14/13, 4:54 AM

Print statements should appear in log, if not- maybe your print statement is after some error and does not get executed?

For OpenERP debugging tool and its usage, look at this question and answer

I dont have any error before print.i enabled debug mode by setting debug_mode = true in /etc/openerp/openerp-server.conf and checking log tail -f /var/log/openerp/openerp-server.log but still its not showing print

on 8/14/13, 5:15 AM
Marvin Taboada
On 6/20/14, 12:03 AM

Hello Anuradha,

I personally prefer to pass the command line argument "--log-level=debug", to the "openerp-server" script, in order to set the log level, instead of using the configuration file.

Several useful options can be passed as command line arguments as well, run "./openerp-server  --help", from the appropriate directory, in order to get the complete list of options and values it accepts if applicable, e.g.: available log levels.

The Python interpreter won't reload your code changes automatically, you will require to restart OpenERP after adding additional logging statements into your code.

I hope this helps.

Abegail Sanchez
On 6/19/14, 11:57 PM

As mentioned above, eclipse will work. You can debug sql query also.

There you can see your cron running

SELECT * FROM ir_cron
                              WHERE numbercall != 0
                                  AND active AND nextcall <= (now() at time zone 'UTC')
                              ORDER BY priority None
SELECT 1 FROM ir_module_module WHERE name=%s AND latest_version=%s ('base', '')
SELECT * FROM ir_cron
                              WHERE numbercall != 0
                                  AND active AND nextcall <= (now() at time zone 'UTC')
                              ORDER BY priority None
SELECT 1 FROM ir_module_module WHERE name=%s AND latest_version=%s ('base', '')
SELECT * FROM ir_cron
                              WHERE numbercall != 0
                                  AND active AND nextcall <= (now() at time zone 'UTC')
                              ORDER BY priority None
SELECT 1 FROM ir_module_module WHERE name=%s AND latest_version=%s ('base', '')
SELECT * FROM ir_cron
                              WHERE numbercall != 0
                                  AND active AND nextcall <= (now() at time zone 'UTC')
                              ORDER BY priority None
SELECT 1 FROM ir_module_module WHERE name=%s AND latest_version=%s ('base', '')
SELECT * FROM ir_cron
                              WHERE numbercall != 0
                                  AND active AND nextcall <= (now() at time zone 'UTC')
                              ORDER BY priority None

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)


Asked: 8/14/13, 4:09 AM
Seen: 27897 times
Last updated: 1/28/16, 4:43 AM