Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] pydantic: Migration to 17.0 #437

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ exclude: |
^graphql_base/|
^graphql_demo/|
^model_serializer/|
^pydantic/|
^rest_log/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
Expand Down
84 changes: 45 additions & 39 deletions pydantic/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ Pydantic
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
:target: https://github.com/OCA/rest-framework/tree/16.0/pydantic
:target: https://github.com/OCA/rest-framework/tree/17.0/pydantic
:alt: OCA/rest-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-pydantic
:target: https://translation.odoo-community.org/projects/rest-framework-17-0/rest-framework-17-0-pydantic
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon provides a utility method that can be used to map odoo record
to a `Pydantic model <https://pydantic-docs.helpmanual.io/>`_.
to a `Pydantic model <https://pydantic-docs.helpmanual.io/>`__.

If you need to make your Pydantic models extendable at runtime, takes a look
at the python package `extendable-pydantic <https://pypi.org/project/extendable_pydantic/>`_
and the odoo addon `extendable <https://github.com/acsone/odoo-addon-extendable>`_
If you need to make your Pydantic models extendable at runtime, takes a
look at the python package
`extendable-pydantic <https://pypi.org/project/extendable_pydantic/>`__
and the odoo addon
`extendable <https://github.com/acsone/odoo-addon-extendable>`__

**Table of contents**

Expand All @@ -43,70 +45,74 @@ and the odoo addon `extendable <https://github.com/acsone/odoo-addon-extendable>
Usage
=====

To support pydantic models that map to Odoo models, Pydantic model instances can
be created from arbitrary odoo model instances by mapping fields from odoo
models to fields defined by the pydantic model. To ease the mapping, the addon
provide a utility class `odoo.addons.pydantic.utils.GenericOdooGetter`.
To support pydantic models that map to Odoo models, Pydantic model
instances can be created from arbitrary odoo model instances by mapping
fields from odoo models to fields defined by the pydantic model. To ease
the mapping, the addon provide a utility class
odoo.addons.pydantic.utils.GenericOdooGetter.

.. code-block:: python
.. code:: python

import pydantic
from odoo.addons.pydantic import utils
import pydantic
from odoo.addons.pydantic import utils

class Group(pydantic.BaseModel):
name: str
class Group(pydantic.BaseModel):
name: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter
class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter

class UserInfo(pydantic.BaseModel):
name: str
groups: List[Group] = pydantic.Field(alias="groups_id")
class UserInfo(pydantic.BaseModel):
name: str
groups: List[Group] = pydantic.Field(alias="groups_id")

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter
class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter

user = self.env.user
user_info = UserInfo.from_orm(user)
user = self.env.user
user_info = UserInfo.from_orm(user)

See the official `Pydantic documentation`_ to discover all the available functionalities.

.. _`Pydantic documentation`: https://pydantic-docs.helpmanual.io/
See the official `Pydantic
documentation <https://pydantic-docs.helpmanual.io/>`__ to discover all
the available functionalities.

Known issues / Roadmap
======================

The `roadmap <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Apydantic>`_
and `known issues <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apydantic>`_ can
be found on GitHub.
The
`roadmap <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Apydantic>`__
and `known
issues <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apydantic>`__
can be found on GitHub.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20pydantic%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20pydantic%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~
-------

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~
------------

* Laurent Mignon <[email protected]>
- Laurent Mignon <[email protected]>
- Tris Doan <[email protected]>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -126,6 +132,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lmignon|

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/pydantic>`_ project on GitHub.
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/17.0/pydantic>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions pydantic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Pydantic",
"summary": """
Utility addon to ease mapping between Pydantic and Odoo models""",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"development_status": "Beta",
"license": "LGPL-3",
"maintainers": ["lmignon"],
Expand All @@ -17,5 +17,5 @@
"external_dependencies": {
"python": ["pydantic", "contextvars", "typing-extensions"]
},
"installable": False,
"installable": True,
}
3 changes: 3 additions & 0 deletions pydantic/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions pydantic/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Laurent Mignon \<<[email protected]>\>
- Tris Doan \<<[email protected]>\>
1 change: 0 additions & 1 deletion pydantic/readme/CONTRIBUTORS.rst

This file was deleted.

8 changes: 8 additions & 0 deletions pydantic/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This addon provides a utility method that can be used to map odoo record
to a [Pydantic model](https://pydantic-docs.helpmanual.io/).

If you need to make your Pydantic models extendable at runtime, takes a
look at the python package
[extendable-pydantic](https://pypi.org/project/extendable_pydantic/) and
the odoo addon
[extendable](https://github.com/acsone/odoo-addon-extendable)
6 changes: 0 additions & 6 deletions pydantic/readme/DESCRIPTION.rst

This file was deleted.

5 changes: 5 additions & 0 deletions pydantic/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The
[roadmap](https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Apydantic)
and [known
issues](https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apydantic)
can be found on GitHub.
3 changes: 0 additions & 3 deletions pydantic/readme/ROADMAP.rst

This file was deleted.

32 changes: 32 additions & 0 deletions pydantic/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
To support pydantic models that map to Odoo models, Pydantic model
instances can be created from arbitrary odoo model instances by mapping
fields from odoo models to fields defined by the pydantic model. To ease
the mapping, the addon provide a utility class
odoo.addons.pydantic.utils.GenericOdooGetter.

``` python
import pydantic
from odoo.addons.pydantic import utils

class Group(pydantic.BaseModel):
name: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter

class UserInfo(pydantic.BaseModel):
name: str
groups: List[Group] = pydantic.Field(alias="groups_id")

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter

user = self.env.user
user_info = UserInfo.from_orm(user)
```

See the official [Pydantic
documentation](https://pydantic-docs.helpmanual.io/) to discover all the
available functionalities.
31 changes: 0 additions & 31 deletions pydantic/readme/USAGE.rst

This file was deleted.

Loading
Loading