Towards idiomatic Python with types for the Odoo ORM
Project description
typodoo
Towards idiomatic Python with types for Odoo models.
This package supports the Odoo Experience 2022 talk (sildes, video).
It works best when a few type annotations are added to the Odoo core.
/!\ This is pre-alpha stuff /!\
What?
pip install typodoo
to monkey patch the Odoo metaclass on Odoo startup.
Then, you can still write this, as usual:
from odoo import models, fields
class ResPartner(models.Model):
_inherit = "res.partner"
friend = fields.Boolean()
industry2_id = fields.Many2one(
'res.partner.industry',
string='Secondary Industry',
required=True,
)
But you can also write this:
from odoo import fields
from odoo.addons.base.models.res_partner import (
Partner, ResPartnerIndustry
)
class ResPartner(Partner):
friend = fields.Boolean()
industry2_id = fields.Many2one[ResPartnerIndustry](
string='Secondary Industry',
)
And also this:
from odoo.addons.my_addon.models.res_partner import ResPartner
partners = ResPartner(self.env).search([])
Why?
Idiomatic python.
Native auto completion in IDEs.
Static type checking.
Development
pip install -e .
Then, copy typodoo_activate.pth
to $VIRTUAL_ENV/lib/python3.10/site-packages
.
Automating this setup is a TODO.
License
typodoo
is distributed under the terms of the
MIT license.
Project details
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
File details
Details for the file typodoo-0.3.tar.gz
.
File metadata
- Download URL: typodoo-0.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c61b7f883688153f103d5c4f7c97dee3af848e79e793a95545211cb0367d2ade |
|
MD5 | 29ca16dad7c915a9dfeb12e732e8f9ab |
|
BLAKE2b-256 | 7c0c363b0a6e6cf64dedd5ab042ed63faa908be1291588759496d65f0646347f |
File details
Details for the file typodoo-0.3-py3-none-any.whl
.
File metadata
- Download URL: typodoo-0.3-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e16017226ed168a4b32c288eed052607d425f844d47003610ec7fbfbf4bcdc5 |
|
MD5 | 6d698939d2a399a89b2a45d87eaf3e25 |
|
BLAKE2b-256 | 288a32105a23c85ca79fd36607beb5d981381f2dcb81d45fb5580448a814f2ea |