Skip to main content

This addon allows you to define simple data models supporting serialization/deserialization

Project description

Beta License: LGPL-3 OCA/rest-framework Translate me on Weblate Try me on Runbot

This addon allows you to define simple data models supporting serialization/deserialization to/from json

Datamodels are Marshmallow models classes that can be inherited as Odoo Models.

Table of contents

Usage

To define your own datamodel you just need to create a class that inherits from odoo.addons.datamodel.core.Datamodel

from marshmallow import fields

from odoo.addons.base_rest import restapi
from odoo.addons.component.core import Component
from odoo.addons.datamodel.core import Datamodel


class PartnerShortInfo(Datamodel):
    _name = "partner.short.info"

    id = fields.Integer(required=True, allow_none=False)
    name = fields.String(required=True, allow_none=False)

class PartnerInfo(Datamodel):
    _name = "partner.info"
    _inherit = "partner.short.info"

    street = fields.String(required=True, allow_none=False)
    street2 = fields.String(required=False, allow_none=True)
    zip_code = fields.String(required=True, allow_none=False)
    city = fields.String(required=True, allow_none=False)
    phone = fields.String(required=False, allow_none=True)
    is_componay = fields.Boolean(required=False, allow_none=False)

As for odoo models, you can extend the base datamodel by inheriting of base.

class Base(Datamodel):
    _inherit = "base"

    def _my_method(self):
        pass

Datamodels are available through the datamodels registry provided by the Odoo’s environment.

class ResPartner(Model):
    _inherit = "res.partner"

    def _to_partner_info(self):
        PartnerInfo = self.env.datamodels["partner.info"]
        partner_info = PartnerInfo(partial=True)
        partner_info.id = partner.id
        partner_info.name = partner.name
        partner_info.street = partner.street
        partner_info.street2 = partner.street2
        partner_info.zip_code = partner.zip
        partner_info.city = partner.city
        partner_info.phone = partner.phone
        partner_info.is_company = partner.is_company
        return partner_info

The Odoo’s environment is also available into the datamodel instance.

class MyDataModel(Datamodel):
    _name = "my.data.model"

    def _my_method(self):
        partners = self.env["res.partner"].search([])

Known issues / Roadmap

The roadmap and known issues can be found on GitHub.

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.

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

Credits

Authors

  • ACSONE SA/NV

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

lmignon

This module is part of the OCA/rest-framework project on GitHub.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file odoo12_addon_datamodel-12.0.3.0.2-py3-none-any.whl.

File metadata

  • Download URL: odoo12_addon_datamodel-12.0.3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5

File hashes

Hashes for odoo12_addon_datamodel-12.0.3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 430390fc43c28a7621ed42ae4e5fbf0439f74d78cd230c9bb4f131533510e0c7
MD5 4ae19f91a8af0eaa7f138a9740cee895
BLAKE2b-256 79bf606b8cb826edc222bad70b9c4e0c357aaf3a19179e5c74299028fc54e189

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page