Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
34457 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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 ??

อวตาร
ละทิ้ง
ผู้เขียน

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

}

]

}

คำตอบที่ดีที่สุด


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.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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





อวตาร
ละทิ้ง
ผู้เขียน

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

คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
How to Debug odoo python via PyCharms แก้ไขแล้ว
4
ธ.ค. 19
10594
0
พ.ย. 23
914
2
ก.ย. 23
1128
0
ก.ย. 21
3190
0
ก.พ. 21
4477