Skip to content

Structure Odoo Projects

Trịnh Anh Ngọc edited this page Mar 11, 2024 · 3 revisions

How do you structure your Odoo projects in PyCharm? After years of programming Odoo using PyCharm, I want to share with you how I do it. I find it working great so far, not only for me but also for my colleagues.

For example, I have the following Odoo related folders:

Basically, there are two ways to structure these folders in PyCharm: (1) using content roots or (2) using project dependencies. Both need to meet the following requirements:

  • Works with multiple Odoo versions and multiple custom addons repositories at the same time without switching between projects and windows.
  • Works well with the Odoo plugin.

Use content roots

This is my preferred structure. The above folders are grouped by Odoo version. One project per Odoo version. In one project, I will add all related folders as the content roots of the project. Here is the step by step:

  • Open the odoo15 folder as the main project.
  • In the same PyCharm window, open the odoo16 folder and choose Attach.
  • Open Settings > Project > Python Interpreter to setup Python interpreters for odoo15 and odoo16 projects.
  • Open Settings > Project > Project Structure. Select the odoo15 project, click Add Content Root to add the following folders: account-invoicing15, stock-logistics-warehouse15. Do the same for the odoo16 project. The result will look like the following screenshot: image

Use project dependencies

This structure is flatter. Each custom addons branch is a separate project. It all depends on another project - the odoo source code. Here is the step by step:

  • Open the odoo15 folder as the main project.
  • In the same PyCharm window, open the account-invoicing15 folder and choose Attach. Do the same for other folders. Once done, we will have the following projects: odoo15, account-invoicing15, stock-logistics-warehouse15, odoo16, account-invoicing16, stock-logistics-warehouse16.
  • Open Settings > Project > Python Interpreter to setup Python interpreters for these projects.
  • Open Settings > Project > Project Dependencies. Select the account-invoicing15 project and set the dependency is the odoo15 project. Do the same for other custom addons projects. The result will look like the following screenshot: image

Custom scopes

To navigate code more efficiently in a multiple Odoo versions workspace like above, you can create custom scopes. I always have several custom scopes, one for each Odoo version. This way I can use these scopes to search for files, symbols,... more efficiently. For example: image

Searching without scope will yield confusing results: image

Searching with a specific scope will yield only relevant results: image

Clone this wiki locally