Skip to content

Commit b31cc17

Browse files
committed
Merge PR #495 into 18.0
Signed-off-by lmignon
2 parents 93d1344 + 33f6caa commit b31cc17

File tree

14 files changed

+778
-0
lines changed

14 files changed

+778
-0
lines changed

pydantic/README.rst

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
========
2+
Pydantic
3+
========
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:63e7e15e47d64ac50e8e639eb39f516a9bf2320a6ef8b1ef925430ed259b5b73
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20+
:target: https://github.com/OCA/rest-framework/tree/18.0/pydantic
21+
:alt: OCA/rest-framework
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-pydantic
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This addon provides a utility method that can be used to map odoo record
32+
to a `Pydantic model <https://pydantic-docs.helpmanual.io/>`__.
33+
34+
If you need to make your Pydantic models extendable at runtime, takes a
35+
look at the python package
36+
`extendable-pydantic <https://pypi.org/project/extendable_pydantic/>`__
37+
and the odoo addon
38+
`extendable <https://github.com/acsone/odoo-addon-extendable>`__
39+
40+
**Table of contents**
41+
42+
.. contents::
43+
:local:
44+
45+
Usage
46+
=====
47+
48+
To support pydantic models that map to Odoo models, Pydantic model
49+
instances can be created from arbitrary odoo model instances by mapping
50+
fields from odoo models to fields defined by the pydantic model. To ease
51+
the mapping, the addon provide a utility class
52+
odoo.addons.pydantic.utils.GenericOdooGetter.
53+
54+
.. code:: python
55+
56+
import pydantic
57+
from odoo.addons.pydantic import utils
58+
59+
class Group(pydantic.BaseModel):
60+
name: str
61+
62+
class Config:
63+
orm_mode = True
64+
getter_dict = utils.GenericOdooGetter
65+
66+
class UserInfo(pydantic.BaseModel):
67+
name: str
68+
groups: List[Group] = pydantic.Field(alias="groups_id")
69+
70+
class Config:
71+
orm_mode = True
72+
getter_dict = utils.GenericOdooGetter
73+
74+
user = self.env.user
75+
user_info = UserInfo.from_orm(user)
76+
77+
See the official `Pydantic
78+
documentation <https://pydantic-docs.helpmanual.io/>`__ to discover all
79+
the available functionalities.
80+
81+
Known issues / Roadmap
82+
======================
83+
84+
The
85+
`roadmap <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Apydantic>`__
86+
and `known
87+
issues <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apydantic>`__
88+
can be found on GitHub.
89+
90+
Bug Tracker
91+
===========
92+
93+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
94+
In case of trouble, please check there if your issue has already been reported.
95+
If you spotted it first, help us to smash it by providing a detailed and welcomed
96+
`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**>`_.
97+
98+
Do not contact contributors directly about support or help with technical issues.
99+
100+
Credits
101+
=======
102+
103+
Authors
104+
-------
105+
106+
* ACSONE SA/NV
107+
108+
Contributors
109+
------------
110+
111+
- Laurent Mignon <[email protected]>
112+
- Tris Doan <[email protected]>
113+
114+
Maintainers
115+
-----------
116+
117+
This module is maintained by the OCA.
118+
119+
.. image:: https://odoo-community.org/logo.png
120+
:alt: Odoo Community Association
121+
:target: https://odoo-community.org
122+
123+
OCA, or the Odoo Community Association, is a nonprofit organization whose
124+
mission is to support the collaborative development of Odoo features and
125+
promote its widespread use.
126+
127+
.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px
128+
:target: https://github.com/lmignon
129+
:alt: lmignon
130+
131+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
132+
133+
|maintainer-lmignon|
134+
135+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/pydantic>`_ project on GitHub.
136+
137+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

pydantic/__init__.py

Whitespace-only changes.

pydantic/__manifest__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2021 ACSONE SA/NV
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
{
5+
"name": "Pydantic",
6+
"summary": """
7+
Utility addon to ease mapping between Pydantic and Odoo models""",
8+
"version": "18.0.1.0.0",
9+
"development_status": "Beta",
10+
"license": "LGPL-3",
11+
"maintainers": ["lmignon"],
12+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
13+
"website": "https://github.com/OCA/rest-framework",
14+
"depends": [],
15+
"data": [],
16+
"demo": [],
17+
"external_dependencies": {
18+
"python": ["pydantic", "contextvars", "typing-extensions"]
19+
},
20+
"installable": True,
21+
}

pydantic/i18n/it.po

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
#
4+
msgid ""
5+
msgstr ""
6+
"Project-Id-Version: Odoo Server 17.0\n"
7+
"Report-Msgid-Bugs-To: \n"
8+
"Last-Translator: Automatically generated\n"
9+
"Language-Team: none\n"
10+
"Language: it\n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: nplurals=2; plural=n != 1;\n"

pydantic/i18n/pydantic.pot

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
#
4+
msgid ""
5+
msgstr ""
6+
"Project-Id-Version: Odoo Server 17.0\n"
7+
"Report-Msgid-Bugs-To: \n"
8+
"Last-Translator: \n"
9+
"Language-Team: \n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: \n"
13+
"Plural-Forms: \n"

pydantic/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

pydantic/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Laurent Mignon \<<[email protected]>\>
2+
- Tris Doan \<<[email protected]>\>

pydantic/readme/DESCRIPTION.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This addon provides a utility method that can be used to map odoo record
2+
to a [Pydantic model](https://pydantic-docs.helpmanual.io/).
3+
4+
If you need to make your Pydantic models extendable at runtime, takes a
5+
look at the python package
6+
[extendable-pydantic](https://pypi.org/project/extendable_pydantic/) and
7+
the odoo addon
8+
[extendable](https://github.com/acsone/odoo-addon-extendable)

pydantic/readme/ROADMAP.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The
2+
[roadmap](https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Apydantic)
3+
and [known
4+
issues](https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apydantic)
5+
can be found on GitHub.

pydantic/readme/USAGE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
To support pydantic models that map to Odoo models, Pydantic model
2+
instances can be created from arbitrary odoo model instances by mapping
3+
fields from odoo models to fields defined by the pydantic model. To ease
4+
the mapping, the addon provide a utility class
5+
odoo.addons.pydantic.utils.GenericOdooGetter.
6+
7+
``` python
8+
import pydantic
9+
from odoo.addons.pydantic import utils
10+
11+
class Group(pydantic.BaseModel):
12+
name: str
13+
14+
class Config:
15+
orm_mode = True
16+
getter_dict = utils.GenericOdooGetter
17+
18+
class UserInfo(pydantic.BaseModel):
19+
name: str
20+
groups: List[Group] = pydantic.Field(alias="groups_id")
21+
22+
class Config:
23+
orm_mode = True
24+
getter_dict = utils.GenericOdooGetter
25+
26+
user = self.env.user
27+
user_info = UserInfo.from_orm(user)
28+
```
29+
30+
See the official [Pydantic
31+
documentation](https://pydantic-docs.helpmanual.io/) to discover all the
32+
available functionalities.

0 commit comments

Comments
 (0)