Skip to main content

Towards idiomatic Python with types for the Odoo ORM

Project description

typodoo

PyPI - Version PyPI - Python Version


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

typodoo-0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

typodoo-0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file typodoo-0.2.tar.gz.

File metadata

  • Download URL: typodoo-0.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for typodoo-0.2.tar.gz
Algorithm Hash digest
SHA256 0762626b81b4fe67b1dba974b581eb40503fcbb2ddb435c639deffe7324c5cb6
MD5 6458ad1af3459d8cbe30fbb9c7bf4f87
BLAKE2b-256 db739e820664ac11f7edf7dfdf3b6c0f82836356be169e68631e2a78c7b70931

See more details on using hashes here.

File details

Details for the file typodoo-0.2-py3-none-any.whl.

File metadata

  • Download URL: typodoo-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for typodoo-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d4c6c98f00ec5b2bc4072997399a77280c8f3521439efcf1fa35d2102b72377
MD5 39bdefe4800cdb682e275abcd322a5f9
BLAKE2b-256 c8e46732b3fda8dcc08f8e2cf2775c2757142b1e49c92edeb38332a48f8976ab

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page