是否可以在Visual Studio代码上运行和调试Odoo?如果是,请与我分享配置。
Visual Studio Code是Microsoft为Windows,Linux和macOS开发的源代码编辑器。它包括对调试,嵌入式Git控件,语法突出显示,智能代码完成,代码片段和代码重构的支持。它是免费和开源的,虽然官方下载是在专有许可下。
答案 0 :(得分:6)
我知道我来晚了,但是我设法与Odoo 11合作。
我的安装路径是“ C:\ Program Files(x86)\ Odoo 11.0 \ server”
现在打开vs代码并转到Workspace设置并将其粘贴:
{
"python.pythonPath": "C:\\Program Files (x86)\\Odoo 11.0\\python\\python.exe",
"python.linting.pylintEnabled": false,
// use this so the autocompleate/goto definition will work with python extension
"python.autoComplete.extraPaths": [
"${workspaceRoot}/odoo/addons",
"${workspaceRoot}/odoo",
"${workspaceRoot}/odoo/openerp/addons"
],
//"python.linting.pylintPath": "optional: path to python use if you have environment path",
"python.linting.enabled": false,
//load the pylint_odoo
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_odoo"
],
"python.formatting.provider": "yapf",
//"python.formatting.yapfPath": "optional: path to python use if you have environment path",
// "python.linting.pep8Path": "optional: path to python use if you have environment path",
"python.linting.pep8Enabled": true,
// add this auto-save option so the pylint will sow errors while editing otherwise
//it will only show the errors on file save
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500,
// The following will hide the compiled file in the editor/ add other file to hide them from editor
"files.exclude": {
"**/*.pyc": true
}
}
保存它并在vs“ C:\ Program Files(x86)\ Odoo 11.0 \ server \ odoo”中打开代码文件夹
然后转到调试设置和一个新的配置文件,并粘贴以下代码:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Odoo",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"console": "externalTerminal",
"program": "${workspaceRoot}\\..\\odoo-bin",
"args": [
"--config=${workspaceRoot}\\..\\odoo.conf",
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"RedirectOutput"
]
}
]
}
,然后点击运行按钮。记住vs代码可能会给您一些警告,请按“忽略”按钮,然后等待控制台打开就可以完成操作。享受调试和编码的乐趣。
别忘了从窗口服务中停止 Odoo服务。
答案 1 :(得分:3)
是的,您甚至可以使用VSCode调试Odoo:
首先,您需要在VSCode中安装Python Extension。
将安装了Odoo的文件夹添加到当前项目中。您可以使用功能Multiroot Workspaces。我认为在这种情况下很方便:在一个文件夹中打开项目模块,在其他文件夹中打开Odoo
然后,如果要开始调试,只需单击“调试”按钮并单击侧栏顶部的滚轮即可。文件launch.json
将打开,您只需将此元素添加到底部。
{
"name": "Python: Odoo",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"console": "externalTerminal",
"program": "${workspaceRoot}/odoo_path/odoo.py",
"args": [
"--config=/odoo_config_path/.odoo_8.conf",
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"RedirectOutput"
]
}
添加后,您已经可以在VSCode下运行Odoo。有关启动配置click here
的详细信息现在您可以像往常一样创建断点。您也可以使用调试器控制台。如果你像我一样使用属性:"console": "externalTerminal"
,你可以同时在外部控制台中显示日志
注意:如果您只想运行odoo,可以使用VSCode中的集成控制台
注2 :我建议同时安装the Odoo Snippets extension。
答案 2 :(得分:0)
我想添加更新的答案,所以我要共享我正在使用的简单launch.json
脚本。该脚本假定odoo位于项目文件夹中。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Odoo",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/odoo-bin",
"console": "integratedTerminal",
"args": [
"--addons-path",
"addons,mymodules",
],
}
]
}
vscode版本:1.39.2(2019年9月)
odoo版本:11
关于launch.json
:https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
答案 3 :(得分:0)
我的设置-Odoo 12,Visual Studio Code 1.40.0,Linux
以Adeel Rizvi的帖子为基础-非常感谢!已针对Linux和较新的VSCode更新。
我一天的大部分时间都花在工作上。我为Odoo使用了多实例设置,这完全没有帮助。
对于调试,我需要整理权限提示,因此我决定以当前用户身份运行调试实例。在接下来的命令中,始终用您的实际用户名替换myuser
。禁止使用我的odoo70
用户,因为它无法访问我的主文件夹(包括调试器)中的vscode内容。
我将Odoo内容复制到/opt/odoo70l
,做了sudo chown -R myuser:users /opt/odoo70l
,并创建了一个新的postgres用户sudo su - postgres -c "createuser --createdb --username postgres --no-createrole --no-superuser --no-password myuser"
,以继续使用对等身份验证。这还需要在配置文件中将数据库用户更改为myuser
-对我来说/opt/odoo70l/odoo70l.conf
。 (请注意,这将使调试实例无法访问以前的数据库-更改它们的所有者,或者在新用户下导出和导入。)我还注释了该日志文件,以便将日志直接打印到终端。
我的工作区位于/opt/odoo-dev/
中,其子文件夹包含带有我要处理的模块的项目。我使用多根工作区来查看基本的Odoo代码。
我的工作区选项(/opt/odoo-dev/workspace-name.code-workspace
):
(我的每个Odoo实例都有自己的python venv-如果不使用它,请记住将python.pythonPath
修改为/usr/bin/python3
或将which python3
指向的任何地方。)< / p>
{
"folders": [
{
"path": "."
},
{
"path": "/opt/odoo70l"
},
],
"settings": {
"python.pythonPath": "/opt/odoo70l/odoo-venv/bin/python3",
"python.linting.pylintEnabled": false,
// use this so the autocompleate/goto definition will work with python extension
"python.autoComplete.extraPaths": [
"/opt/odoo70l/odoo/addons",
"/opt/odoo70l/odoo",
"/opt/odoo70l/odoo/odoo/addons"
],
//"python.linting.pylintPath": "optional: path to python use if you have environment path",
"python.linting.enabled": false,
//load the pylint_odoo
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_odoo"
],
"python.formatting.provider": "yapf",
//"python.formatting.yapfPath": "optional: path to python use if you have environment path",
// "python.linting.pep8Path": "optional: path to python use if you have environment path",
"python.linting.pep8Enabled": true,
// add this auto-save option so the pylint will sow errors while editing otherwise
//it will only show the errors on file save
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500,
// The following will hide the compiled file in the editor/ add other file to hide them from editor
"files.exclude": {
"**/*.pyc": true
}
},
}
我的/opt/odoo-dev/.vscode/launch.json
(仅第一个块很重要,其余的保留在默认的VSCode配置中,以防您还要进行其他Python调试):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Odoo 12 myuser",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"console": "externalTerminal",
"program": "/opt/odoo70l/odoo/odoo-bin",
"args": [
"--config=/opt/odoo70l/odoo70l.conf",
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
},
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "enter-your-module-name-here",
"console": "integratedTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
}
答案 4 :(得分:-2)
让我们说可能,
使用ubuntu操作系统进行Odoo官方开发。
对于odoo 11.0大多数建议使用插件的subline或gedit是最好的开发工具。
ubuntu的Visula工作室 https://www.youtube.com/watch?v=aY4Rhmv5P_Q
自2011年以来,我们已经使用ubuntu在gedit上建立了很多odoo代码。此外,atom
https://atom.io/是编辑内容的好工具。
我特别关注gedit,它占用的内存非常少,速度也很快。 万一你有大RAM,是的。这个视觉工作室效果很好。