Skip to content

Commit 55b997e

Browse files
[MIG] datamodel: Migration to 19.0
1 parent 8647185 commit 55b997e

16 files changed

Lines changed: 274 additions & 235 deletions

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ exclude: |
44
^base_rest/|
55
^base_rest_auth_api_key/|
66
^base_rest_pydantic/|
7-
^datamodel/|
87
^extendable/|
98
^fastapi/|
109
^pydantic/|

datamodel/README.rst

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
=========
26
Datamodel
37
=========
@@ -13,26 +17,27 @@ Datamodel
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1822
:alt: License: LGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20-
:target: https://github.com/OCA/rest-framework/tree/16.0/datamodel
24+
:target: https://github.com/OCA/rest-framework/tree/19.0/datamodel
2125
:alt: OCA/rest-framework
2226
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-datamodel
27+
:target: https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-0-datamodel
2428
:alt: Translate me on Weblate
2529
.. |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=16.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=19.0
2731
:alt: Try me on Runboat
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
3034

31-
This addon allows you to define simple data models supporting serialization/deserialization
32-
to/from json
35+
This addon allows you to define simple data models supporting
36+
serialization/deserialization to/from json
3337

34-
Datamodels are `Marshmallow models <https://github.com/sv-tools/marshmallow-objects>`_ classes that can be inherited as Odoo
35-
Models.
38+
Datamodels are `Marshmallow
39+
models <https://github.com/sv-tools/marshmallow-objects>`__ classes that
40+
can be inherited as Odoo Models.
3641

3742
**Table of contents**
3843

@@ -42,118 +47,122 @@ Models.
4247
Usage
4348
=====
4449

45-
To define your own datamodel you just need to create a class that inherits from
46-
``odoo.addons.datamodel.core.Datamodel``
50+
To define your own datamodel you just need to create a class that
51+
inherits from ``odoo.addons.datamodel.core.Datamodel``
4752

48-
.. code-block:: python
53+
.. code:: python
4954
50-
from marshmallow import fields
55+
from marshmallow import fields
5156
52-
from odoo.addons.base_rest import restapi
53-
from odoo.addons.component.core import Component
54-
from odoo.addons.datamodel.core import Datamodel
57+
from odoo.addons.base_rest import restapi
58+
from odoo.addons.component.core import Component
59+
from odoo.addons.datamodel.core import Datamodel
5560
5661
57-
class PartnerShortInfo(Datamodel):
58-
_name = "partner.short.info"
62+
class PartnerShortInfo(Datamodel):
63+
_name = "partner.short.info"
5964
60-
id = fields.Integer(required=True, allow_none=False)
61-
name = fields.String(required=True, allow_none=False)
65+
id = fields.Integer(required=True, allow_none=False)
66+
name = fields.String(required=True, allow_none=False)
6267
63-
class PartnerInfo(Datamodel):
64-
_name = "partner.info"
65-
_inherit = "partner.short.info"
68+
class PartnerInfo(Datamodel):
69+
_name = "partner.info"
70+
_inherit = "partner.short.info"
6671
67-
street = fields.String(required=True, allow_none=False)
68-
street2 = fields.String(required=False, allow_none=True)
69-
zip_code = fields.String(required=True, allow_none=False)
70-
city = fields.String(required=True, allow_none=False)
71-
phone = fields.String(required=False, allow_none=True)
72-
is_componay = fields.Boolean(required=False, allow_none=False)
72+
street = fields.String(required=True, allow_none=False)
73+
street2 = fields.String(required=False, allow_none=True)
74+
zip_code = fields.String(required=True, allow_none=False)
75+
city = fields.String(required=True, allow_none=False)
76+
phone = fields.String(required=False, allow_none=True)
77+
is_componay = fields.Boolean(required=False, allow_none=False)
7378
79+
As for odoo models, you can extend the base datamodel by inheriting of
80+
base.
7481

75-
As for odoo models, you can extend the `base` datamodel by inheriting of `base`.
82+
.. code:: python
7683
77-
.. code-block:: python
84+
class Base(Datamodel):
85+
_inherit = "base"
7886
79-
class Base(Datamodel):
80-
_inherit = "base"
87+
def _my_method(self):
88+
pass
8189
82-
def _my_method(self):
83-
pass
90+
Datamodels are available through the datamodels registry provided by the
91+
Odoo's environment.
8492

85-
Datamodels are available through the `datamodels` registry provided by the Odoo's environment.
93+
.. code:: python
8694
87-
.. code-block:: python
95+
class ResPartner(Model):
96+
_inherit = "res.partner"
8897
89-
class ResPartner(Model):
90-
_inherit = "res.partner"
91-
92-
def _to_partner_info(self):
93-
PartnerInfo = self.env.datamodels["partner.info"]
94-
partner_info = PartnerInfo(partial=True)
95-
partner_info.id = partner.id
96-
partner_info.name = partner.name
97-
partner_info.street = partner.street
98-
partner_info.street2 = partner.street2
99-
partner_info.zip_code = partner.zip
100-
partner_info.city = partner.city
101-
partner_info.phone = partner.phone
102-
partner_info.is_company = partner.is_company
103-
return partner_info
98+
def _to_partner_info(self):
99+
PartnerInfo = self.env.datamodels["partner.info"]
100+
partner_info = PartnerInfo(partial=True)
101+
partner_info.id = partner.id
102+
partner_info.name = partner.name
103+
partner_info.street = partner.street
104+
partner_info.street2 = partner.street2
105+
partner_info.zip_code = partner.zip
106+
partner_info.city = partner.city
107+
partner_info.phone = partner.phone
108+
partner_info.is_company = partner.is_company
109+
return partner_info
104110
105111
The Odoo's environment is also available into the datamodel instance.
106112

107-
.. code-block:: python
113+
.. code:: python
108114
109-
class MyDataModel(Datamodel):
110-
_name = "my.data.model"
115+
class MyDataModel(Datamodel):
116+
_name = "my.data.model"
111117
112-
def _my_method(self):
113-
partners = self.env["res.partner"].search([])
118+
def _my_method(self):
119+
partners = self.env["res.partner"].search([])
114120
115121
.. warning::
116122

117-
The `env` property into a Datamodel instance is mutable. IOW, you can't rely
118-
on information (context, user) provided by the environment. The `env` property
119-
is a helper property that give you access to the odoo's registry and must
120-
be use with caution.
123+
The env property into a Datamodel instance is mutable. IOW, you can't
124+
rely on information (context, user) provided by the environment. The
125+
env property is a helper property that give you access to the odoo's
126+
registry and must be use with caution.
121127

122128
Known issues / Roadmap
123129
======================
124130

125-
The `roadmap <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Adatamodel>`_
126-
and `known issues <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Adatamodel>`_ can
127-
be found on GitHub.
131+
The
132+
`roadmap <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Adatamodel>`__
133+
and `known
134+
issues <https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Adatamodel>`__
135+
can be found on GitHub.
128136

129137
Bug Tracker
130138
===========
131139

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

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

139147
Credits
140148
=======
141149

142150
Authors
143-
~~~~~~~
151+
-------
144152

145153
* ACSONE SA/NV
146154

147155
Contributors
148-
~~~~~~~~~~~~
156+
------------
157+
158+
- Laurent Mignon <laurent.mignon@acsone.eu>
149159

150-
* Laurent Mignon <laurent.mignon@acsone.eu>
151-
* `Tecnativa <https://www.tecnativa.com>`_:
160+
- `Tecnativa <https://www.tecnativa.com>`__:
152161

153-
* Carlos Roca
162+
- Carlos Roca
154163

155164
Maintainers
156-
~~~~~~~~~~~
165+
-----------
157166

158167
This module is maintained by the OCA.
159168

@@ -173,6 +182,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
173182

174183
|maintainer-lmignon|
175184

176-
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/datamodel>`_ project on GitHub.
185+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/19.0/datamodel>`_ project on GitHub.
177186

178187
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

datamodel/__manifest__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"summary": """
77
This addon allows you to define simple data models supporting
88
serialization/deserialization""",
9-
"version": "16.0.1.0.1",
9+
"version": "19.0.1.0.0",
1010
"license": "LGPL-3",
1111
"development_status": "Beta",
1212
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
1313
"maintainers": ["lmignon"],
1414
"website": "https://github.com/OCA/rest-framework",
15-
"external_dependencies": {"python": ["marshmallow", "marshmallow-objects>=2.0.0"]},
16-
"installable": False,
15+
"external_dependencies": {
16+
"python": ["marshmallow<4.0.0", "marshmallow-objects>=2.0.0"]
17+
},
1718
}

datamodel/builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def build_registry(self, datamodels_registry, states=None, exclude_addons=None):
6363
# lookup all the installed (or about to be) addons and generate
6464
# the graph, so we can load the datamodels following the order
6565
# of the addons' dependencies
66-
graph = modules.graph.Graph()
67-
graph.add_module(self.env.cr, "base")
66+
graph = modules.module_graph.ModuleGraph(self.env.cr)
67+
graph.extend(["base"])
6868

6969
query = "SELECT name FROM ir_module_module WHERE state IN %s "
7070
params = [tuple(states)]
@@ -74,7 +74,7 @@ def build_registry(self, datamodels_registry, states=None, exclude_addons=None):
7474
self.env.cr.execute(query, params)
7575

7676
module_list = [name for (name,) in self.env.cr.fetchall() if name not in graph]
77-
graph.add_modules(self.env.cr, module_list)
77+
graph.extend(module_list)
7878

7979
for module in graph:
8080
self.load_datamodels(module.name, datamodels_registry=datamodels_registry)

datamodel/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"

datamodel/readme/CONTRIBUTORS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Laurent Mignon \<<laurent.mignon@acsone.eu>\>
2+
3+
- [Tecnativa](https://www.tecnativa.com):
4+
5+
> - Carlos Roca

datamodel/readme/CONTRIBUTORS.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

datamodel/readme/DESCRIPTION.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This addon allows you to define simple data models supporting
2+
serialization/deserialization to/from json
3+
4+
Datamodels are [Marshmallow
5+
models](https://github.com/sv-tools/marshmallow-objects) classes that
6+
can be inherited as Odoo Models.

datamodel/readme/DESCRIPTION.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

datamodel/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%3Adatamodel)
3+
and [known
4+
issues](https://github.com/OCA/rest-framework/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Adatamodel)
5+
can be found on GitHub.

0 commit comments

Comments
 (0)