تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
6 الردود
34434 أدوات العرض

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
4
ديسمبر 19
10586
0
نوفمبر 23
910
2
سبتمبر 23
1096
0
سبتمبر 21
3158
0
فبراير 21
4457