This question has been flagged
7 Replies
29112 Views
settings.json:
{    
"python.pythonPath": "C:\\VirtualEnvs\\odoov12\\Scripts\\python.exe",
"python.autoComplete.extraPaths": [
        "${workspaceRoot}/odoo/addons",
        "${workspaceRoot}/odoo",
        "${workspaceRoot}/odoo/openerp/addons" ],
        "python.linting.enabled": true,
    "python.linting.pylintArgs": ["--load-plugins", "pylint_odoo"],
    "python.formatting.provider": "yapf",
    "python.linting.pycodestyleEnabled": true,
    "python.linting.pylintEnabled": false,
    "python.linting.pylamaEnabled": true,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 500,
    "files.exclude": {
        "**/*.pyc": true 
                       },

launch.json:
{    // 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-Zea",
 "type": "python",
 "request": "launch",
 "stopOnEntry": false,
 "program": "${workspaceFolder}/odoo/odoo-bin",
 "pythonPath": "C:\\VirtualEnvs\\odoov12\\Scripts\\python.exe",
 "args": [
 "--config",
 "${workspaceFolder}/environments/zaeelektronik/zae-odoo.conf",
 "-u",
 "zae_elektoronik",
 "-u",
 "tcmb_currency_rate_live"
 "-d",
 "zae_local",
 ],
 "console": "integratedTerminal",
 },
]
}  

Here is my settings.json and launch.json. I start to debugging (Pressing F5) debugging is started and after 2 sec later debug has finished. The status bar is orange when i m pressing F5 but after that the status bar immadiately blue again. I use Odoo v12. By the way I can develop Odoo using Pycharm. It works on it . But it doesn't work on VS Code. Can you help me ? What I am doing wrong ?

​ ​

Avatar
Discard
Best Answer

To debug your app in Visual Studio Code, you’ll first need to set up your launch configuration file - launch.json.
Click on the Configure gear icon on the Debug view top bar, choose your debug environment and Visual Studio Code will generate a launch.json file under your workspace’s .vscode folder.

{
    "name": "Python",
    "type": "python",
    "request": "launch",
    "stopOnEntry": false,
    "pythonPath": "${config.python.pythonPath}",
    //"program": "${file}", use this to debug opened file.
    "program": "${workspaceRoot}/Path/To/odoo.py",
    "args": [
      "-c ${workspaceRoot}/sampleconfigurationfile.cfg"
    ],
    "cwd": "${workspaceRoot}",
    "console": "externalTerminal",
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "RedirectOutput"
    ]
},

use “args” to specify any options like database, config, or user name and password.

I hope this helps.

Avatar
Discard
Best Answer

Well, I guess there is better way that there is no need to add code to odoo itself

https://gist.github.com/kerbrose/e646aaf9daece42b46091e2ca0eb55d0

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Odoo: Attach",
            "type": "python",
            "request": "attach",
            "port": 8879,
            "debugServer": 8888,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/mnt/extra-addons", //path to custom addons inside docker
                },
                {
                    "localRoot": "/dev/odoo", //odoo source code
                    "remoteRoot": "/odoo",    //path to source inside docker
                }
            ],
            "logToFile": true
            //"preLaunchTask": "init docker",
            //"postDebugTask": "stop docker"
        }
    ]
}

please note that your docker.dev file should include

RUN pip3 install -U debugpy

then you will be running the debugger not odoo as
docker run --rm -p 8888:3001 -p 8879:8069 odoo /usr/bin/python3 -m debugpy --listen 0.0.0.0:3001 /usr/bin/odoo --db_user=odoo --db_host=db --db_password=odoo
or
docker-compose run --rm -p 8888:3001 -p 8879:8069 odoo /usr/bin/python3 -m debugpy --listen 0.0.0.0:3001 /usr/bin/odoo --db_user=odoo --db_host=db --db_password=odoo
Avatar
Discard
Best Answer
Put this in your launch.json file. This worked for me.
{
 "name": "Python: Odoo",     
 "type": "python",           
 "request": "launch",            
"pythonPath": "Give the entire path of python from the virtual environment you are using",            
"console": "integratedTerminal", 
 "program": "${workspaceFolder}/odoo-bin",
 "args": ["start", "--database=Your database name", "--db-filter=Your database name", "-i base",  "--addons-path=Give complete path for yopur addons",            ],
 "cwd": "${workspaceRoot}",
 "env": {},
 "envFile": "${workspaceRoot}/.env",
}
Avatar
Discard
Author

When I m trying to debug I am getting this error " Could not create database `my database name`. (FATAL: role "Asus" does not exist) ". But my database already exist . I looked for the solution on web but i couldn't find for Windows 10.

This worked for me as well! I just removed the '-i base' command.

Perhaps it could help you as well? What happens if you don't set a database name but only '"args": ["start", "-i base", "--addons-path=Give complete path for yopur addons", ]?