Tool to generate Odoo model type classes for better IDE support
Project description
odoo-typing-classes-generator
Trying to Improve the Developer Experience by Generating Typing Classes for Odoo Models
This is project at this stage is only a proof of concept.
For a given Odoo module, this tool scans its dependencies and introspects any classes inheriting from
odoo.models.BaseModel in order to generate corresponding typing classes for every Odoo model.
Installation
$ uv sync
$ source .venv/bin/activate
$ pip install -e .
$ odoo-typing-classes-generator --help
or
$ pip install odoo-typing-classes-generator
$ odoo-typing-classes-generator --help
Usage: Generating the Typing Classes
$ odoo-typing-classes-generator --modules=foobar --addons-path=odoo/addons
This command will create the following files within the odoo/addons/foobar folder:
typing/__init__.py: either empty, or only containing the classes names depending on options; and__init__.pyi: containing the detailed definitions of all Odoo models based on the module and its dependencies.
[Required] --modules TEXT
Comma-separated list of Comma-separated list of Odoo modules to generate the typing classes for.
[Required] --addons-path TEXT
Path where the modules are located, relative to the current working directory.
[Flag] --generate-all-classes
When set, the typing/__init__.py files will be created with all the available classes.
This is useful if you want to have all the classes available for typing, even if you don't use them all.
Warning: this can create a very large file, depending on the number of models in the module and its dependencies.
By default, the typing/__init__.py files will be created empty if they don't exist yet.
You will have to manually add the classes you want to use for typing, in the format:
class ClassName:
pass
You can check in the __init__.pyi to see the available classes, all of them have a field _name = "[Odoo Model Name]"
you can search for.
Alternatively, if you have an Odoo model abc.def_ghi, the typing class name will be AbcDefGhi.
Note: You should most likely avoid to put the stub files into your VCS.
Usage: Use the Typing Classes In Code
It is very important to import the typing.models module for this to work (see reasons below).
You can, of course, use an alias to avoid name collisions.
For example:
from odoo import models
from odoo.addons.foobar import typing as models_typing
class ResPartner(models.Model):
_inherit = "res.partner"
def test(self, companies: models_typing.ResCompany) -> models_typing.ResUsers:
...
Warning: if you import the typing class directly from the typing module,
you will have no autocomplete suggestion from your IDE*.
*I don't know why this is the case, plus I only tested this script with IntelliJ IDEA 2025.2.1 (Ultimate Edition),
if you have an explanation, you can add it here, thanks! ❤️
In Case of Missing Classes in the typing/__init__.py File
Without the --generate-all-classes Option
You can just add them manually. If the autocomplete still doesn't work for one or more classes, check if they are present in the stub file. If they are absent, check if you have missing dependencies in your manifest.
With the --generate-all-classes Option
Check if you have missing dependencies in your manifest.
General Process
- Scan the module and all its dependencies recursively by reading the manifest files, while doing that every time
we find an Odoo model, we collect the following information:
- whether the model is abstract, transient or concrete;
- the list of inherited models;
- all defined Odoo fields;
- all the non-private / named-mangled methods and functions with their signatures;
- for basic fields we map them to built in types;
- for the related fields we only store the "related" value; and
- for other fields referencing another Odoo model, we only store the model name;
- then, for each Odoo model, we aggregate all the definitions: the list of inherited models, the list of fields, the list of functions and methods;
- then, the type of all related fields is resolved; and
- finally, we write the typing classes into a file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file odoo_typing_classes_generator-17.0.0.0.2.tar.gz.
File metadata
- Download URL: odoo_typing_classes_generator-17.0.0.0.2.tar.gz
- Upload date:
- Size: 98.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a92f170a59532cd072592571d867cceffbf8d9db369d4d4c50caf0f9505eae4
|
|
| MD5 |
4acddd095345d17124f6798dba11d54b
|
|
| BLAKE2b-256 |
96873d6605aa9876baa61e66f6f0c794b80d1e3a0858ad15a95cb34c37c9a8d6
|
Provenance
The following attestation bundles were made for odoo_typing_classes_generator-17.0.0.0.2.tar.gz:
Publisher:
publish.yml on alexandregaldeano/odoo-typing-classes-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
odoo_typing_classes_generator-17.0.0.0.2.tar.gz -
Subject digest:
8a92f170a59532cd072592571d867cceffbf8d9db369d4d4c50caf0f9505eae4 - Sigstore transparency entry: 598494896
- Sigstore integration time:
-
Permalink:
alexandregaldeano/odoo-typing-classes-generator@3e6bb917df922f72afd8a1c1f2f8ce8643789d61 -
Branch / Tag:
refs/tags/v17.0.0.0.2 - Owner: https://github.com/alexandregaldeano
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e6bb917df922f72afd8a1c1f2f8ce8643789d61 -
Trigger Event:
release
-
Statement type:
File details
Details for the file odoo_typing_classes_generator-17.0.0.0.2-py3-none-any.whl.
File metadata
- Download URL: odoo_typing_classes_generator-17.0.0.0.2-py3-none-any.whl
- Upload date:
- Size: 45.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
928986630e033c125dc4387b00d905160b3a2d26a570f118cbba3f0e2b0c7df5
|
|
| MD5 |
91c94d575a01d1be0f685c6b557542cd
|
|
| BLAKE2b-256 |
9deb5e27394ddd4482ea4b62768a07f3176695e8f189f522669e956128b36a62
|
Provenance
The following attestation bundles were made for odoo_typing_classes_generator-17.0.0.0.2-py3-none-any.whl:
Publisher:
publish.yml on alexandregaldeano/odoo-typing-classes-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
odoo_typing_classes_generator-17.0.0.0.2-py3-none-any.whl -
Subject digest:
928986630e033c125dc4387b00d905160b3a2d26a570f118cbba3f0e2b0c7df5 - Sigstore transparency entry: 598494901
- Sigstore integration time:
-
Permalink:
alexandregaldeano/odoo-typing-classes-generator@3e6bb917df922f72afd8a1c1f2f8ce8643789d61 -
Branch / Tag:
refs/tags/v17.0.0.0.2 - Owner: https://github.com/alexandregaldeano
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e6bb917df922f72afd8a1c1f2f8ce8643789d61 -
Trigger Event:
release
-
Statement type: