本文使用的系统环境为ubuntu 18.04,odoo版本为odoo11,虚拟环境使用Virtualenv。
-
配置Virtual Environments的路径。打开File -> Preferences -> Settings, 在右侧的USER SETTINGS中添加 "python.venvPath": "~/env","~/env"为Virtual Environments路径。
{ "python.venvPath": "~/env", } 复制代码
-
配置launch.json。打开Debug -> Open Configurations, 选择python,${workspaceFolder}为工作目录,-c -u -d 等参数均可在args中填写。
{ "name": "Odoo", "type": "python", "request": "launch", "program": "${workspaceFolder}/odoo/odoo-bin", "args": [ "-c", "${workspaceFolder}/odoo.conf" ] } 复制代码
-
用vscode打开整个odoo工作目录会有一个警告 “Visual Studio Code is unable to watch for file changes in this large workspace”。如果不处理,debug会出现问题。这里可以参照vscode官网给出的解决方案。
When you see this notification, it indicates that the VS Code file watcher is running out of handles because the workspace is large and contains many files. The current limit can be viewed by running:
cat /proc/sys/fs/inotify/max_user_watches 复制代码
The limit can be increased to its maximum by editing /etc/sysctl.conf and adding this line to the end of the file:
fs.inotify.max_user_watches=524288 复制代码
The new value can then be loaded in by running sudo sysctl -p. Note that Arch Linux works a little differently, view this page for advice.
-
如果安装了pylint,代码会有一堆pylint的错误提示,但是不影响odoo运行。如果不爽的话可以卸载pylint,也可以在USER SETTINGS中添加以下代码,将pylint的enable设置为false。
"python.linting.enabled": false, 复制代码