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=========
26Datamodel
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.
4247Usage
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
122128Known 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
129137Bug Tracker
130138===========
131139
132140Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues >`_.
133141In case of trouble, please check there if your issue has already been reported.
134142If 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
137145Do not contact contributors directly about support or help with technical issues.
138146
139147Credits
140148=======
141149
142150Authors
143- ~~~~~~~
151+ -------
144152
145153* ACSONE SA/NV
146154
147155Contributors
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
155164Maintainers
156- ~~~~~~~~~~~
165+ -----------
157166
158167This 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
178187You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
0 commit comments