如何在 Visual Studio Ubuntu 中的代码上开发(运行 和调试)Odoo v11 中的模块?
How to develop (run and debug) modules in Odoo v11 on Visual Studio Code in Ubuntu?
是否可以在 Visual Studio 代码上 运行 和调试 Odoo?如果是,请分享我的配置。
Visual Studio Code is a source code editor developed by Microsoft for Windows, Linux and macOS. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. It is free and open-source, although the official download is under a proprietary license.
假设可能,
Odoo 官方开发完成 ubuntu 操作系统。
对于 odoo 11.0 大多数建议使用带插件的 subline 或 gedit 最好的开发工具。
ubuntu 中的 Visula 工作室
https://www.youtube.com/watch?v=aY4Rhmv5P_Q
自 2011 年至今,我们使用 ubuntu 在 gedit 上构建了很多 odoo 代码。另外 atom
https://atom.io/ 是编辑内容的好工具。
我特别关注 gedit,它占用的内存非常少,而且速度很快。
如果你有大内存,是的。这个 visual studio 效果很好。
是的,您甚至可以使用 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。
我知道我有点晚了,但我已经成功地使用了 Odoo 11。
我的安装路径是"C:\Program Files (x86)\Odoo 11.0\server"
现在打开 vs 代码并转到工作区设置并粘贴此内容:
{
"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 code 可能会给你一些警告按下忽略按钮并等待控制台打开你就完成了。享受调试和编码。
不要忘记从 window 服务中停止 Odoo 服务。
我想添加更新的答案,所以我分享了我正在使用的简单 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
我的设置 - Odoo 12,Visual Studio代码 1.40.0,Linux
基于 Adeel Rizvi 的 post - 非常感谢!更新了 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
指向。)
{
"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"
}
]
}
是否可以在 Visual Studio 代码上 运行 和调试 Odoo?如果是,请分享我的配置。
Visual Studio Code is a source code editor developed by Microsoft for Windows, Linux and macOS. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. It is free and open-source, although the official download is under a proprietary license.
假设可能,
Odoo 官方开发完成 ubuntu 操作系统。
对于 odoo 11.0 大多数建议使用带插件的 subline 或 gedit 最好的开发工具。
ubuntu 中的 Visula 工作室 https://www.youtube.com/watch?v=aY4Rhmv5P_Q
自 2011 年至今,我们使用 ubuntu 在 gedit 上构建了很多 odoo 代码。另外 atom
https://atom.io/ 是编辑内容的好工具。
我特别关注 gedit,它占用的内存非常少,而且速度很快。 如果你有大内存,是的。这个 visual studio 效果很好。
是的,您甚至可以使用 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。
我知道我有点晚了,但我已经成功地使用了 Odoo 11。
我的安装路径是"C:\Program Files (x86)\Odoo 11.0\server"
现在打开 vs 代码并转到工作区设置并粘贴此内容:
{
"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 code 可能会给你一些警告按下忽略按钮并等待控制台打开你就完成了。享受调试和编码。
不要忘记从 window 服务中停止 Odoo 服务。
我想添加更新的答案,所以我分享了我正在使用的简单 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
我的设置 - Odoo 12,Visual Studio代码 1.40.0,Linux
基于 Adeel Rizvi 的 post - 非常感谢!更新了 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
指向。)
{
"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"
}
]
}