{"id":20619704,"url":"https://github.com/twtrubiks/odoo-development-environment-tutorial","last_synced_at":"2025-10-28T19:07:01.435Z","repository":{"id":55819420,"uuid":"228523001","full_name":"twtrubiks/odoo-development-environment-tutorial","owner":"twtrubiks","description":"建立 odoo 開發環境 ( source code )","archived":false,"fork":false,"pushed_at":"2024-03-12T00:30:44.000Z","size":31,"stargazers_count":41,"open_issues_count":0,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T19:53:43.911Z","etag":null,"topics":["development-environment","docker","odoo","odoo13","python","tutorial","vscode"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twtrubiks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-17T03:13:08.000Z","updated_at":"2024-08-10T13:49:43.000Z","dependencies_parsed_at":"2024-03-12T01:46:48.234Z","dependency_job_id":null,"html_url":"https://github.com/twtrubiks/odoo-development-environment-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fodoo-development-environment-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fodoo-development-environment-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fodoo-development-environment-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fodoo-development-environment-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twtrubiks","download_url":"https://codeload.github.com/twtrubiks/odoo-development-environment-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067775,"owners_count":21207395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["development-environment","docker","odoo","odoo13","python","tutorial","vscode"],"created_at":"2024-11-16T12:12:19.486Z","updated_at":"2025-10-28T19:07:01.429Z","avatar_url":"https://github.com/twtrubiks.png","language":null,"readme":"# odoo-development-environment-tutorial\n\n建立 odoo 開發環境 ( source code )\n\n本篇文章將教大家如何使用 odoo source code 建立開發環境,\n\n如果你想要用 docker 建立, 可參考 [利用 docker 快速建立 odoo 環境](https://github.com/twtrubiks/odoo-docker-tutorial).\n\n延伸閱讀 [手把手教大家撰寫 odoo 的 addons - 進階篇](https://github.com/twtrubiks/odoo-demo-addons-tutorial)\n\n## 目錄\n\n1. [建立 odoo 開發環境](https://github.com/twtrubiks/odoo-development-environment-tutorial#odoo-development-environment-tutorial) - [Youtube Tutorial - 如何建立 odoo 開發環境 - odoo13 - 從無到有](https://youtu.be/Yazci5Rd0p4)\n\n2. [Odoo VSCode Debug](https://github.com/twtrubiks/odoo-development-environment-tutorial#odoo-vscode-debug) - [Youtube Tutorial - 如何在 VS Code 中 Debug - odoo13](https://youtu.be/cV8Sm5yYR38)\n\n環境為 Ubuntu 18.04, 非常不推薦 Windows (你會踩雷) :scream:\n\n## Prepare\n\n需要準備 Ubuntu 18.04 + odoo (source code) + postgresql + wkhtmltopdf + VS Code。\n\nodoo 我們留在最後再安裝 :smile:\n\n### Ubuntu 18.04\n\n前面說過了, 不推薦 Windows 開發環境, 你會被 debug 搞死, 相信我 :smirk:\n\n而且會遇到不少很怪的問題。\n\n注意 :exclamation: :exclamation: 如果你是使用 Ubuntu 20.04, 預設的 python 是 3.8,\n\n對 odoo 來說太新了, 安裝會有很多問題, 建議安裝 python3.6 (這版本裝 odoo 比較好建立環境)\n\n`sudo apt-get install -y python3.6-venv`\n\n### postgresql\n\n這邊你可以選擇安裝到本機, 但我自己是喜歡把 db 這部份安裝到 docker,\n\n[docker-compose.yml](https://github.com/twtrubiks/odoo-development-environment-tutorial/blob/master/odoo-db/docker-compose.yml)\n\n```ymal\nversion: '3.5'\nservices:\n\n  db:\n    image: postgres:10.9\n    ports:\n      - \"5432:5432\"\n    environment:\n      - POSTGRES_DB=postgres\n      - POSTGRES_USER=odoo\n      - POSTGRES_PASSWORD=odoo\n      - PGDATA=/var/lib/postgresql/data/pgdata\n    volumes:\n      - odoo-db-data:/var/lib/postgresql/data/pgdata\n\nvolumes:\n  odoo-db-data:\n```\n\n直接執行 `docker-compose up` 即可, 也可以讓他在背景跑 `docker-compose up -d`。\n\n![alt tag](https://i.imgur.com/IcSt8mn.png)\n\n然後建議依照 [在 Linux 中自動啟動 docker](https://github.com/twtrubiks/docker-tutorial/tree/master/docker-auto-run-linux) 讓他開機自動啟動。\n\n(這樣就不用每次都要去啟動 db 了)\n\n### pgadmin4\n\n可參考 [利用 docker 快速建立 pgadmin4 以及 Ubuntu 本機如何安裝 pgadmin4](https://github.com/twtrubiks/docker-pgadmin4-tutorial)\n\n建議把 postgresql-client-12 安裝起來, 不然 odoo 可能無法還原備份 db.\n\n`sudo apt install postgresql-client-12`\n\n這邊提醒一下, 主要是看你的 postgresql 是使用哪個版本的,\n\n如果你同時安裝了 postgresql12 以及 postgresql13,\n\n你就再安裝 `sudo apt install postgresql-client-13`.\n\n可以到 `/usr/share/postgresql` 確認你安裝了哪些版本.\n\n### wkhtmltopdf\n\n尋找對應的版本安裝即可 [wkhtmltopdf](https://wkhtmltopdf.org/downloads.html)\n\n```cmd\nwkhtmltopdf --version\n```\n\n![alt tag](https://i.imgur.com/aLaE0Dh.png)\n\n這邊推薦的版本為 0.12.5。\n\n如果你在 odoo 列印 PDF 時, 遇到以下的錯誤\n\n```text\nWkhtmltopdf failed (error code: -8). Message: b'' error\n```\n\n![alt tag](https://i.imgur.com/0uac0Ok.png)\n\n這是字型的問題, 請安裝字型\n\n```cmd\nsudo apt install ttf-mscorefonts-installer\n```\n\n### odoo\n\nclone odoo repo\n\n```cmd\ngit clone https://github.com/odoo/odoo.git\n```\n\n確認是否為 odoo 13 branch ( 預設為 odoo 13 )\n\n![alt tag](https://i.imgur.com/hYmP7W4.png)\n\n接著不要急, 來建立 odoo python 環境\n\n```cmd\npython3 -m venv odoo13\n```\n\n![alt tag](https://i.imgur.com/TrIwBRY.png)\n\n如果出現以下錯誤,\n\n![alt tag](https://i.imgur.com/wRxLIjU.png)\n\n請安裝 python3-venv\n\n```cmd\nsudo apt-get install python3-venv\n```\n\n然後再次執行 `python3 -m venv odoo13` 即可。\n\n接著啟動環境,\n\n```cmd\nsource odoo13/bin/activate\n```\n\n![alt tag](https://i.imgur.com/Ci0F62d.png)\n\n接著是安裝 requirements.txt ( 這個檔案在 odoo 的 source code 中 )\n\n```cmd\npip3 install -r requirements.txt\n```\n\n我會建議安裝 requirements.txt 前, 先把 wheel 裝起來\n\n```cmd\npip3 install wheel\n```\n\n![alt tag](https://i.imgur.com/CwW8PiY.png)\n\n安裝 requirements.txt 時, 可能會出現類似下面的錯誤訊息。\n\n可能出現的錯誤一,\n\n```cmd\nerror: command 'x86_64-linux-gnu-gcc' failed with exit status 1\n```\n\n執行以下指令即可, 可參考 [issues/2115](https://github.com/scrapy/scrapy/issues/2115)\n\n```cmd\nsudo apt-get install python3 python-dev python3-dev \\\n     build-essential libssl-dev libffi-dev \\\n     libxml2-dev libxslt1-dev zlib1g-dev \\\n     python-pip\n```\n\n這邊補充一下, 建議依照你的 python 版本安裝, 例如你今天安裝了 python3.8,\n\n就執行 `sudo apt-get install python3.8-dev`\n\n以此類推.\n\n可能出現的錯誤二,\n\npython-ldap 安裝失敗,執行以下指令即可,\n\n```cmd\nsudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev\n```\n\n可能出現的錯誤三,\n\n有時候 psycopg2 會安裝失敗(odoo15), 建議可以改安裝 psycopg2-binary.\n\n```cmd\npip3 install psycopg2-binary\n```\n\n可能出現的錯誤四,\n\n有時候更新 python 時 (自己遇過一次), 某個套件竟然自己壞了,\n\n錯誤訊息如下,\n\n```text\nImportError: /python3.6/site-packages/lxml/etree.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyFPE_jbuf\n```\n\n解法方法,\n\n```cmd\npip3 install --upgrade --force-reinstall --no-binary :all: lxml==3.7.1\n```\n\n基本上到這邊可以稍微休息一下.\n\n解決後再重新安裝 requirements.txt 即可.\n\n### odoo16\n\n這邊紀錄一下, odoo16 環境的建立,\n\n首先是 python 的版本, python 3.9 or python 3.8 都可以,\n\n如果出現底下的錯誤訊息,\n\n```text\nERROR: Failed building wheel for python-ldap\n```\n\n一樣安裝下面指令就對了(請注意自己的 python 版本)\n\n```python\nsudo apt-get install build-essential python3.9-dev libsasl2-dev libldap2-dev libssl-dev\n```\n\n另外是如果你有佈署, 會發現有一點點不一樣,\n\n因為 odoo16 開始 longpolling 變 websocket 了 (效能更好),\n\n所以設定上會有點不同, 詳細說明請參考官方文件\n\n[https://www.odoo.com/documentation/16.0/administration/install/deploy.html](https://www.odoo.com/documentation/16.0/administration/install/deploy.html)\n\n### 設定 odoo 環境\n\n先確認 db 有啟動。\n\n設定 [odoo.conf](odoo.conf), 我會建議建立一個資料夾, 比較好維護,\n\n```conf\n[options]\naddons_path = /home/twtrubiks/work/odoo13/addons\ndata_dir = /home/twtrubiks/Downloads/odoo-git/odoo-data\ndb_host = localhost\n```\n\n`addons_path` 就是 addons 的位置，通常都會有很多，使用逗號隔開即可。\n\n( 我自己是都會給 addons 權限 `sudo chmod -R 777 folder` , 因為之前有踩過雷 )\n\n`data_dir` 保存 odoo 資料夾。\n\n`db_host` 為 db 的 host。\n\n![alt tag](https://i.imgur.com/LntDbDj.png)\n\n執行以下指令\n\n```cmd\npython3 odoo-bin -w odoo -r odoo -c /home/twtrubiks/work/odoo13/config/odoo.conf\n```\n\n`-w` db_password\n\n`-r` db_user\n\n`-c` config 路徑. 當然, 你也可以不要用 config , 直接在 command 中下設定\n\n`--stop-after-init` 當初始化結束後, 就會自動關閉 server (不管安裝成功或失敗)\n\n更多可參考 [Command-line interface: odoo-bin](https://www.odoo.com/documentation/13.0/reference/cmdline.html)。\n\n![alt tag](https://i.imgur.com/gNkDfJ3.png)\n\n瀏覽 [http://0.0.0.0:8069/](http://0.0.0.0:8069/), 成功看到畫面了,\n\n![alt tag](https://i.imgur.com/xEALOWg.png)\n\n### Odoo VSCode Debug\n\n[Youtube Tutorial - 如何在 VS Code 中 Debug - odoo13](https://youtu.be/cV8Sm5yYR38)\n\n開發環境非常建議使用 Linux , 我使用 Ubuntu 18.04。\n\n( 注意, windows 用戶需要做其他的設定, 否則你會發現無論如何啟用 debug 時, 都會直接關閉 )\n\n如果不懂 VSCode, 可參考 [Python in Visual Studio Code](https://github.com/twtrubiks/vscode_python_note)。\n\nVSCode 的設定可參考 [launch.json](https://github.com/twtrubiks/odoo-development-environment-tutorial/blob/master/.vscode/launch.json)\n\n```json\n{\n    // Use IntelliSense to learn about possible attributes.\n    // Hover to view descriptions of existing attributes.\n    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n    \"version\": \"0.2.0\",\n    \"configurations\": [\n        {\n            \"name\": \"odoo\",\n            \"type\": \"python\",\n            \"request\": \"launch\",\n            // \"stopOnEntry\": true,\n            \"pythonPath\": \"/home/twtrubiks/Documents/venv/odoo13/bin/python3\",\n            \"program\": \"${workspaceFolder}/odoo-bin\",\n            \"args\": [\n                \"-w\",\n                \"odoo\",\n                \"-r\",\n                \"odoo\",\n                // \"-d\",\n                // \"odoo\",\n                \"-c\",\n                \"/home/twtrubiks/work/odoo13/config/odoo.conf\"\n            ]\n        }\n    ]\n}\n```\n\n`pythonPath` 設定 python 環境 ( venv 的位置 )。\n\n`program` odoo-bin 的位置。\n\n`-d` 指定 odoo database。\n\n先把 Expense (hr_expense) 裝起來 (我們將使用它來測試中斷點)，\n\n![alt tag](https://i.imgur.com/Yf4nHww.png)\n\n建立中斷點，中斷位置是 `addons/hr_expense/models/hr_expense.py` 裡的 `def create`\n(當建立檔案時, 會進入這個 function 中)\n\n![alt tag](https://i.imgur.com/SV4glxI.png)\n\n開啟 VSCode debug ( 快捷按鍵 F5 ),\n\n![alt tag](https://i.imgur.com/9jU39HC.png)\n\n到 odoo 中建立一筆 hr_expense, 當你要產生一筆 sheet 時,\n\n![alt tag](https://i.imgur.com/ptXxcXa.png)\n\n成功進入中斷點\n\n![alt tag](https://i.imgur.com/QPc994W.png)\n\n#### Odoo VSCode Debug - attach\n\n這邊補充另一種方法 debug, 使用 attach 的方式,\n\n`request` 主要有 `launch` 和 `attach`,\n\n需要安裝 `pip install debugpy`,\n\n可參考 [Python Debugger](https://github.com/twtrubiks/vscode_python_note?tab=readme-ov-file#python-debugger),\n\n[launch.json](https://github.com/twtrubiks/odoo-development-environment-tutorial/blob/master/.vscode/launch.json) 設定如下,\n\n```json\n{\n    \"version\": \"0.2.0\",\n    \"configurations\": [\n        {\n            \"name\": \"odoo attach\",\n            \"type\": \"debugpy\",\n            \"request\": \"attach\",\n            \"connect\": {\n                \"host\": \"localhost\",\n                \"port\": 19000\n            },\n        },\n    ]\n}\n```\n\n先打開一個 terminal 執行\n\n```cmd\npython3 -m debugpy --listen 0.0.0.0:19000 odoo-bin -d odoo -c config/odoo.conf\n```\n\n注意兩邊設定的 port 要一樣, 這邊統一設定 19000 port,\n\n再開一個 terminal 去執行 odoo vscode 的中斷點, 即可順利 debug.\n\n通常這種方式使用在已經執行的外部程式, 或是你執行在 docker 中.\n\n### 說明 dbfilter\n\n這邊特別說明一下 [odoo.conf](odoo.conf) 中的 dbfilter\n\n```conf\n[options]\n......\n;The '^' means start of line and the '$' end of line,\n;so '^%d$' only filter db with name 'hostname' following the example.\n;dbfilter = ^%d$\n```\n\n簡單說, 就是可以透過 dbfilter 去選擇(濾)對應的 db (透過網址),\n\n因為一個 odoo 可以有非常多的 db, 但你可能不想讓A客戶看到B客戶的資料庫,\n\n就很適合使用 dbfilter 這個參數.\n\n`dbfilter = ^%d$` 這個 `^` 代表的是開始的符號, `$` 代表的是結束的符號.\n\n所以如果今天這樣設定, db 名稱有, `twtrubiks`  `twtrubiks01`  `twtrubiks02`,\n\n然後你的網址是 `www.twtrubiks.com`, 當你進去網址時, 只會看到 `twtrubiks` 這個 db :exclamation:\n\n如果你也想看到 `twtrubiks01`  `twtrubiks02`, 這樣要改成 `dbfilter = ^%d`\n\n也就是把 `$` 拿掉.\n\n看文字說明可能很複雜 :scream: 大家可以自己玩玩看, 其實是不難的哦 :smile:\n\n延伸閱讀 [手把手教大家撰寫 odoo 的 addons - 進階篇](https://github.com/twtrubiks/odoo-demo-addons-tutorial)\n\n## Reference\n\n* [odoo13 documentation](https://www.odoo.com/documentation/13.0/setup/install.html#linux)\n* [Odoo](https://www.odoo.com/)\n\n## Donation\n\n文章都是我自己研究內化後原創，如果有幫助到您，也想鼓勵我的話，歡迎請我喝一杯咖啡 :laughing:\n\n綠界科技ECPAY ( 不需註冊會員 )\n\n![alt tag](https://payment.ecpay.com.tw/Upload/QRCode/201906/QRCode_672351b8-5ab3-42dd-9c7c-c24c3e6a10a0.png)\n\n[贊助者付款](http://bit.ly/2F7Jrha)\n\n歐付寶 ( 需註冊會員 )\n\n![alt tag](https://i.imgur.com/LRct9xa.png)\n\n[贊助者付款](https://payment.opay.tw/Broadcaster/Donate/9E47FDEF85ABE383A0F5FC6A218606F8)\n\n## 贊助名單\n\n[贊助名單](https://github.com/twtrubiks/Thank-you-for-donate)\n\n## License\n\nMIT license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fodoo-development-environment-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwtrubiks%2Fodoo-development-environment-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fodoo-development-environment-tutorial/lists"}