PyCharm Odoo 2022.6

Hello world!

I have finally completed the features that I had planned for this release. I hope you all continue to ẹnjoy using the Odoo plugin as much as I enjoy developing it.


Type hints for recordsets

What is your favorite talks at Odoo Experience 2022? For me, it's Towards idiomatic Python with types for the Odoo ORM by Stéphane Bidoul. It's nice to see future improvements to Odoo ORM to leverage the power of IDEs. However, I'm sure we still need more support from IDEs to fully understand the Odoo ORM. Today, I'm excited to share with you how we can add type hints for Odoo recordsets, a much loved feature that I have implemented for this release. There are three ways to specify type for a recordset:

1. Use imported model class definition

Use imported model class

This is the recommended way to do it. When you use a model class definition (origin or inheritances) to specify type for a object, the Odoo plugin will infer it as the corresponding Odoo model instead of just the class definition. This means all inheritance features will be taken into account for the type. You can also use this to specify type in docstrings and comments.

2. Use the magic alias odoo.model.*

Use the magic alias odoo.model.*

If you feel too lazy to import a class and use it for type hint, you can use the magic alias odoo.model.*. For example, odoo.model.res_partner would be understood as the model res.partner. Because the odoo.model.* doesn't exist at runtime, you must put it in a string if using the annotation syntax as the above screenshot. For docstrings and comments, you can use it without enclosing it in quotes.

3. Use model name directly

Use model name directly

If your type hint is just a simple model name, you can use the model name directly. This only applies for type hints in docstrings and comments.


Downstream fixes for PyCharm issues

PyCharm is really powerful IDE for Python developers. However, likes other softwares, it contains a lot of issues which you can see at https://youtrack.jetbrains.com/issues/PY. While working on Odoo, I discovered a lot of PyCharm issues and reported them to JetBrains. I think it will takes a long time until they address it so I have planned to speedup the process by submitting some PRs on the JetBrains GitHub. In the meantime, I have already included some fixes in the Odoo plugin. You can see it in the Odoo plugin change notes.


Odoo 16

Lately I have been spending a lot of time updating odoo-stubs. I also just updated it to support Odoo 16. You can clone the branch 16.0 and use it in your Odoo 16 projects. Support for the new features in Odoo 16 will be included in the next releases of the Odoo plugin.


In addition to the above highlights, this release also includes a lot of bug fixes. You can find the full change notes at https://plugins.jetbrains.com/plugin/13499-odoo.

in News