问题
I am working with OpenERP 6.1 and i am not able to debug the python code by giving print statements in the python code.
This was quite easy/possible with OpenERP 6.0 where we give the server path followed by module name and database name to debug the code.
How can i achieve this with OpenERP 6.1??
Please help!! Thanks in advance..
回答1:
Hi friend you can install ipython. Using ipython you can debug openerp 6.1 at command prompt. kindly make sure that you have installed these packages before hands.
sudo apt-get install python-dateutil python-feedparser python-gdata python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi
I took this list from http://www.theopensourcerer.com/2012/02/22/how-to-install-openerp-6-1-on-ubuntu-10-04-lts/
you can also try pycharm.
回答2:
To debug your Openerp+python code in eclipse, start eclipse in debug perspective and follow the given steps:
1: Stop your openERP running server by pressing "ctr+c".
2: In eclipse go to Menu "Run/Debug Configurations". In configuration window under "Python Run", create new debug configuration(Double click on 'Python Run').
3: After creating new debug configuration follow the given steps:
3.1: In "Main" tab under "Project", select the "server" project or folder (in which Openerp Server resides) from your workspace.
3.2: Write location of 'openerp-server' under "Main Module".
Ex: ${workspace_loc:server/openerp-server}.
3.3: In "Arguments" tab under "Program Arguments", click on button "Variables" and new window will appear.
3.4: Then create new "Variable" by clicking on "Edit Variables" button and new window will appear.
3.5: Press on "New" button and give your addons path as value.
Ex: --addons ../addons,../your_module_path
3.6: Press Ok in all the opened windows and then "Apply".
4: Now into "PyDev Package Explorer" view go to 6.1/server and right click on "openerp-server" file, Select 'Debug As --> Python Run'.
5: Now in "Console" you can see your server has been started.
6: Now open your .py file which you want to debug and set a break-point.
7: Now start your module's form from 'gtk' or 'web-client' and execution will stop when execution will reach to break-point.
8: Now enjoy by debugging your code by pressing "F5, F6, F7" and you can see value of your variables.
回答3:
I run the 6.1 server under Eclipse and PyDev without any problems. That lets me add breakpoints and step through the code. Here are the arguments I use:
--addons-path ${workspace_loc:openerp-addons-trunk},${workspace_loc:openerp-web-trunk}/addons --config ${workspace_loc:openerp-config/src/server.config}
The two breakpoints I find most useful are at either end of the RPC call. On the server side, I put a breakpoint on this line in netsvc.dispatch_rpc():
result = ExportService.getService(service_name).dispatch(method, params)
I don't debug the client as often, and not all requests come through the same path, but one useful breakpoint is the first line of rpc.tinySocket_gw.execute().
Of course, both these breakpoints see a lot of traffic, so I only use them if I'm exploring some feature I'm not familiar with, and I don't know where the code will execute. It can also be useful to put a condition on the breakpoint so it only triggers when a request comes through for a specific model or parameter value.
Here is the config file I use:
[options]
debug_mode = False
admin_passwd = ******
db_user = ******
db_password = *******
price_accuracy = 5
smtp_server = **********
ftp_server_port = 8022
ftp_server_passive_ports = 8192:8447
translate_data = False
#log_level = debug_rpc_answer
回答4:
Check that you have:
logfile = None
in your openerp-server.conf, that gives you the log through the standard output.
Does it helps ?
回答5:
First: import logging
Then :
def ExampleFunction(self,cr,uid,ids,context):
log = logging.getLogger("ExampleClass -- ExampleFunction")
log.info('test')
return True
And in your openerp folder /server/server/openerp-server.log
file
you will see the log.info
content here ( ExampleClass -- ExampleFunction: test)
来源:https://stackoverflow.com/questions/10087899/how-to-debug-python-code-in-openerp-6-1