Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
6 Odpowiedzi
34199 Widoki

i want set red point on any line and see debug mod

Awatar
Odrzuć
Najlepsza odpowiedź

You can use the following manual to configure VSCode for debugging Odoo using Docker:

https://cetmix.com/blog/cetmix-blog-2/odoo-development-using-visual-studio-code-and-docker-1

Awatar
Odrzuć
Najlepsza odpowiedź

Hello friends, try the configuration that was marked as an answer but I get "Failler to attach (connect ECONNREFUSED 172.18.0.3:3000)" inside the container according to point 3 but with the ip of the container and copy the json to my debug file and can anything help me ??

Awatar
Odrzuć
Autor

Hi Edgar, did you run first container and after attached debugger? if no try this, if yes give me your launch.json and docker inspect result

{

"version": "0.2.0",

"configurations": [

{

"name": "Odoo: Attach",

"type": "python",

"request": "attach",

"port": 8069,

"debugServer": 8888,

"host": "localhost",

"pathMappings": [

{

"localRoot": "${workspaceFolder}/addons",

"remoteRoot": "/mnt/extra-addons", //path to custom addons inside docker

}

],

"logToFile": true

}

]

}

Najlepsza odpowiedź


set the following configurations in launch.json (Menu: Debug > Add Configuration.. ) of visual studio code
start odoo from Debug >Strat Debugging 

"configurations": [{
   "name": "Python: Odoo",
   "type": "python",
   "request": "launch",
   "program": "${workspaceFolder}/workspace/odoo-bin",
   "args": ["start", "--database=12.0", "--db-filter=12.0", "--addons-path=workspace/addons,enterprise"],
},
]​
​Note: change path according to your working directory.

I don't know how to set up it for a docker container.

Awatar
Odrzuć
Autor Najlepsza odpowiedź

steps:

1) find odoo-bin file and add new lines:

import subprocess
import time
process = subprocess.Popen("hostname -I | awk '{print $BASH_ARGV}'", stdout=subprocess.PIPE, shell=True)
while process.wait():
    time.sleep(0.1)
output, err = process.communicate()
host = output.split()[-1].decode("utf-8") 
print(host)
try:
    import ptvsd
except ImportError:
    subprocess.call('pip install ptvsd --user', shell=True)
    import ptvsd
ptvsd.enable_attach(address = (host, 3000))

where host var is IP address remote, you can find it in output terminal or run next command:

docker inspect odoo_container

in my case it was 172.25.0.4

2) create new dict in launch.json:

{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 3000,
    "host": "host var value", // 172.25.0.4
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
 ]
}

3) it is all. now you can add in any place of your code "breakpoint()" and activate debug mode

and when this part of code will be called debugger will work in vscode





Awatar
Odrzuć
Autor

if you using git for original odoo you can use "git update-index --assume-unchanged odoo-bin" that git dont triggering on this file

Najlepsza odpowiedź

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
Awatar
Odrzuć
Najlepsza odpowiedź

https://dev.to/kerbrose/how-to-remote-debugging-odoo-docker-images-python-based-framework-4o2h has a more up to date answer.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
gru 19
10474
0
lis 23
863
2
wrz 23
1059
0
wrz 21
3079
0
lut 21
4401