Skip to content
Open
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 @@ -5,7 +5,6 @@ exclude: |
^base_rest_auth_api_key/|
^base_rest_pydantic/|
^extendable/|
^pydantic/|
^rest_log/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
Expand Down
47 changes: 20 additions & 27 deletions pydantic/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pydantic
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bf754ec770116cffb9eee07a08eb62409c1868dfd0f765c017156da1d8242df5
!! source digest: sha256:cffcb5f5c45000bae7dfe3cbf3c9c8c39e5573567ec1b08c2ee4bf56e4f24a18
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -21,25 +21,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/18.0/pydantic
:target: https://github.com/OCA/rest-framework/tree/19.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-18-0/rest-framework-18-0-pydantic
:target: https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-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=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=19.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 (>= v2) <https://docs.pydantic.dev/>`__.

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>`__
and the `odoo addon
extendable <https://pypi.org/project/odoo-addon-extendable>`__

**Table of contents**

Expand All @@ -51,36 +51,28 @@ 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.
fields from odoo models to fields defined by the pydantic model.

To ease the mapping, the addon provide an utility class (using
``pydantic>2.0``) ``odoo.addons.pydantic.utils.PydanticOdooBaseModel``:

.. code:: python

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

class Group(pydantic.BaseModel):
name: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter
class Group(PydanticOdooBaseModel):
name: str

class UserInfo(pydantic.BaseModel):
class UserInfo(PydanticOdooBaseModel):
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.
See the official `Pydantic documentation <https://docs.pydantic.dev/>`__
to discover all the available functionalities.

Known issues / Roadmap
======================
Expand All @@ -97,7 +89,7 @@ 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:%2018.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:%2019.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.

Expand All @@ -114,6 +106,7 @@ Contributors

- Laurent Mignon <laurent.mignon@acsone.eu>
- Tris Doan <tridm@trobz.com>
- Pierre Verkest <pierre@verkest.fr>

Maintainers
-----------
Expand All @@ -136,6 +129,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/18.0/pydantic>`_ project on GitHub.
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/19.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": "18.0.1.0.1",
"version": "19.0.1.0.0",
"development_status": "Beta",
"license": "LGPL-3",
"maintainers": ["lmignon"],
Expand All @@ -17,5 +17,5 @@
"external_dependencies": {
"python": ["pydantic>=2.0.0", "contextvars", "typing-extensions"]
},
"installable": False,
"installable": True,
}
1 change: 1 addition & 0 deletions pydantic/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Laurent Mignon \<<laurent.mignon@acsone.eu>\>
- Tris Doan \<<tridm@trobz.com>\>
- Pierre Verkest \<<pierre@verkest.fr>\>
5 changes: 2 additions & 3 deletions pydantic/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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 (>= v2)](https://docs.pydantic.dev/).

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)
the [odoo addon extendable](https://pypi.org/project/odoo-addon-extendable)
25 changes: 9 additions & 16 deletions pydantic/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
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.
fields from odoo models to fields defined by the pydantic model.


To ease the mapping, the addon provide an utility class (using `pydantic>2.0`) `odoo.addons.pydantic.utils.PydanticOdooBaseModel`:

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

class Group(pydantic.BaseModel):
name: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter
class Group(PydanticOdooBaseModel):
name: str

class UserInfo(pydantic.BaseModel):
class UserInfo(PydanticOdooBaseModel):
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
documentation](https://docs.pydantic.dev/) to discover all the
available functionalities.
42 changes: 17 additions & 25 deletions pydantic/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,16 @@ <h1>Pydantic</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bf754ec770116cffb9eee07a08eb62409c1868dfd0f765c017156da1d8242df5
!! source digest: sha256:cffcb5f5c45000bae7dfe3cbf3c9c8c39e5573567ec1b08c2ee4bf56e4f24a18
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/pydantic"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-pydantic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/19.0/pydantic"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-0-pydantic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon provides a utility method that can be used to map odoo record
to a <a class="reference external" href="https://pydantic-docs.helpmanual.io/">Pydantic model</a>.</p>
to a <a class="reference external" href="https://docs.pydantic.dev/">Pydantic model (&gt;= v2)</a>.</p>
<p>If you need to make your Pydantic models extendable at runtime, takes a
look at the python package
<a class="reference external" href="https://pypi.org/project/extendable_pydantic/">extendable-pydantic</a>
and the odoo addon
<a class="reference external" href="https://github.com/acsone/odoo-addon-extendable">extendable</a></p>
and the <a class="reference external" href="https://pypi.org/project/odoo-addon-extendable">odoo addon
extendable</a></p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -400,34 +400,25 @@ <h1>Pydantic</h1>
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<p>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.</p>
fields from odoo models to fields defined by the pydantic model.</p>
<p>To ease the mapping, the addon provide an utility class (using
<tt class="docutils literal">pydantic&gt;2.0</tt>) <tt class="docutils literal">odoo.addons.pydantic.utils.PydanticOdooBaseModel</tt>:</p>
<pre class="code python literal-block">
<span class="kn">import</span><span class="w"> </span><span class="nn">pydantic</span><span class="w">
</span><span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.pydantic</span><span class="w"> </span><span class="kn">import</span> <span class="n">utils</span><span class="w">
<span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.pydantic.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">PydanticOdooBaseModel</span><span class="w">

</span><span class="k">class</span><span class="w"> </span><span class="nc">Group</span><span class="p">(</span><span class="n">pydantic</span><span class="o">.</span><span class="n">BaseModel</span><span class="p">):</span><span class="w">
</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="w">

</span> <span class="k">class</span><span class="w"> </span><span class="nc">Config</span><span class="p">:</span><span class="w">
</span> <span class="n">orm_mode</span> <span class="o">=</span> <span class="kc">True</span><span class="w">
</span> <span class="n">getter_dict</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">GenericOdooGetter</span><span class="w">
</span><span class="k">class</span><span class="w"> </span><span class="nc">Group</span><span class="p">(</span><span class="n">PydanticOdooBaseModel</span><span class="p">):</span><span class="w">
</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="w">

</span><span class="k">class</span><span class="w"> </span><span class="nc">UserInfo</span><span class="p">(</span><span class="n">pydantic</span><span class="o">.</span><span class="n">BaseModel</span><span class="p">):</span><span class="w">
</span><span class="k">class</span><span class="w"> </span><span class="nc">UserInfo</span><span class="p">(</span><span class="n">PydanticOdooBaseModel</span><span class="p">):</span><span class="w">
</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="w">
</span> <span class="n">groups</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Group</span><span class="p">]</span> <span class="o">=</span> <span class="n">pydantic</span><span class="o">.</span><span class="n">Field</span><span class="p">(</span><span class="n">alias</span><span class="o">=</span><span class="s2">&quot;groups_id&quot;</span><span class="p">)</span><span class="w">

</span> <span class="k">class</span><span class="w"> </span><span class="nc">Config</span><span class="p">:</span><span class="w">
</span> <span class="n">orm_mode</span> <span class="o">=</span> <span class="kc">True</span><span class="w">
</span> <span class="n">getter_dict</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">GenericOdooGetter</span><span class="w">

</span><span class="n">user</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="w">
</span><span class="n">user_info</span> <span class="o">=</span> <span class="n">UserInfo</span><span class="o">.</span><span class="n">from_orm</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</pre>
<p>See the official <a class="reference external" href="https://pydantic-docs.helpmanual.io/">Pydantic
documentation</a> to discover all
the available functionalities.</p>
<p>See the official <a class="reference external" href="https://docs.pydantic.dev/">Pydantic documentation</a>
to discover all the available functionalities.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
Expand All @@ -442,7 +433,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20pydantic%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20pydantic%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -458,6 +449,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
<li>Pierre Verkest &lt;<a class="reference external" href="mailto:pierre&#64;verkest.fr">pierre&#64;verkest.fr</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -471,7 +463,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/lmignon"><img alt="lmignon" src="https://github.com/lmignon.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/18.0/pydantic">OCA/rest-framework</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/19.0/pydantic">OCA/rest-framework</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions pydantic/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_pydantic_generic_odoo_getter
Loading
Loading