如何在Ubuntu的Visual Studio代码上开发Odoo v11中的(运行和调试)模块?

2024-09-28 19:24:49 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以在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.


Tags: and代码odoosourceforbyiscode
3条回答

我想添加更新的答案,因此我正在共享我正在使用的简单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月)

奥多版本:11

关于launch.jsonhttps://code.visualstudio.com/docs/editor/debugging#_launch-configurations

是的,您甚至可以使用VSCode调试Odoo:

首先,需要在VSCode中安装Python Extension

将安装Odoo的文件夹添加到当前项目中。您可以使用功能Multiroot Workspaces。我认为在这种情况下很方便:在一个文件夹中打开项目模块,在另一个文件夹中打开Odoo

然后,如果您想开始调试,只需单击Debug按钮,然后单击侧边栏顶部的控制盘。文件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",则可以同时在外部控制台中显示日志

enter image description here

注意:如果只想运行odoo,可以在VSCode中使用集成控制台

注意2:我建议也安装the Odoo Snippets extension

我知道我有点晚了,但我已经设法和奥多11一起工作了。

我的安装路径是“C:\程序文件(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:\程序文件(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服务。

相关问题 更多 >