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

mftmpeh8  于 2023-02-04  发布在  其他
关注(0)|答案(5)|浏览(106)

是否可以在Visual Studio代码上运行和调试Odoo?如果可以,请与我分享配置。
Visual Studio Code是Microsoft开发的一个源代码编辑器,支持Windows、Linux和macOS操作系统,支持调试、嵌入式Git控件、语法高亮、智能代码完成、代码片段和代码重构。它是免费开源的,但官方下载需要获得专有许可。

mwg9r5ms

mwg9r5ms1#

我知道我有点晚了,但我已经设法与奥多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代码可能会给予你一些警告,按忽略按钮,等待控制台打开,你就完成了。享受调试和编码。
不要忘记从窗口服务停止Odoo服务

dzjeubhm

dzjeubhm2#

是的,您甚至可以使用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。有关启动配置的详细信息,请单击此处
现在您可以像往常一样创建断点。您也可以使用调试器控制台。如果您使用属性:"console": "externalTerminal",您可以同时在外部控制台中显示日志

注意:如果只想运行odoo,可以使用VSCode中的集成控制台
注2:我建议也安装the Odoo Snippets extension

kiz8lqtg

kiz8lqtg3#

我想添加更新的答案,所以我分享简单的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

smtd7mpg

smtd7mpg4#

我的设置- Odoo 12,Visual Studio代码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):
(Each我的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"
        }
    ]
}
zphenhs4

zphenhs45#

假设有可能,
Odoo官方开发完成ubuntu操作系统。
对于odoo 11.0大多数建议subline或gedit与插件最伟大的开发工具。
ubuntu https://www.youtube.com/watch?v=aY4Rhmv5P_Q中的Visula工作室
从2011年到现在,我们已经在gedit和ubuntu上编译了很多odoo代码,atomhttps://atom.io/也是编辑内容的好工具。
我特别关心的是gedit,它占用的内存很少,速度也给予。如果你有很大的内存,是的。这个visual studio工作得很好。

相关问题