Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How to Debug python code in open erp

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
debugprint
16 Besvarelser
73724 Visninger
Avatar
Anuradha

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?

5
Avatar
Kassér
Avatar
Thierry Godin
Bedste svar

Hi,

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
    _logger.error(msg)

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

4
Avatar
Kassér
Anuradha
Forfatter

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

Anuradha
Forfatter
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
     _logger.debug('helooooooooooooooooooooo')
     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
Avatar
Serpent Consulting Services Pvt. Ltd.
Bedste svar

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.

3
Avatar
Kassér
Avatar
Leonardo Donelli
Bedste svar

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.
 

3
Avatar
Kassér
Pascal Tremblay

Thanks I like it!

Avatar
Oleg Orlov
Bedste svar

Simple howto debugging openerp7 with intellij idea on windows.

Prerequests:

  • 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!
0
Avatar
Kassér
Avatar
Alejandro Perez Cosio
Bedste svar

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!

Regards

 

0
Avatar
Kassér
Sah Vinay Mahabir

I got this error when i added in called function in odoo

also i have install ipdb

Traceback (most recent call last):

File "/var/lib/odoo10/odoo/addons/base/ir/ir_cron.py", line 119, in _callback

getattr(model, method_name)(*args)

File "/var/lib/odoo/addons/10.0/allip_provu_phone/models/mac_address.py", line 116, in syncMacAddressProvuOrder

updateResponse = baseClass().updateInventoryForProvuPhoneOrder(product_itemlist, item_mac)

File "/var/lib/odoo/addons/10.0/allip_provu_phone/base/base_class.py", line 180, in updateInventoryForProvuPhoneOrder

import ipdb; ipdb.set_trace()

File "/usr/lib/python2.7/site-packages/ipdb/__main__.py", line 93, in set_trace

p = _init_pdb(context).set_trace(frame)

File "/usr/lib/python2.7/site-packages/ipdb/__main__.py", line 76, in _init_pdb

p = Pdb(def_colors)

File "/usr/lib/python2.7/site-packages/IPython/terminal/debugger.py", line 15, in __init__

self.pt_init()

File "/usr/lib/python2.7/site-packages/IPython/terminal/debugger.py", line 38, in pt_init

self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)

AttributeError: 'TerminalInteractiveShell' object has no attribute '_eventloop'

Avatar
Temur
Bedste svar

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.

0
Avatar
Kassér
Yulybaseball

Is this for versions 7 and 8 only? I'm using version 11; Had to use logging module, ```python print() ``` doesn't work.

Avatar
Bedste svar

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

0
Avatar
Kassér
Anuradha
Forfatter

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

Avatar
Rodney Pantonial
Bedste svar

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.

0
Avatar
Kassér
Avatar
Abegail Sanchez
Bedste svar

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', '7.0.1.3')
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', '7.0.1.3')
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', '7.0.1.3')
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', '7.0.1.3')
SELECT * FROM ir_cron
                              WHERE numbercall != 0
                                  AND active AND nextcall <= (now() at time zone 'UTC')
                              ORDER BY priority None

0
Avatar
Kassér
Avatar
eoin ahern
Bedste svar

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

0
Avatar
Kassér
eoin ahern

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

Avatar
Marvin Taboada
Bedste svar

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.

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
debugging python code
debug python print
Avatar
Avatar
Avatar
2
mar. 15
14338
Webhook. How can i send webhook by execute code?
debug
Avatar
0
nov. 25
5
Facing trouble with my appointment section
debug
Avatar
0
okt. 25
735
ValueError: Wrong value for ir.ui.view.type: 'tree'in Odoo18 Løst
debug
Avatar
Avatar
1
sep. 25
1367
Custom Route splitting return transfers into two different returns.
debug
Avatar
0
aug. 25
1782
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now