OdooWiki OCA HUB
Uncategorised License: LGPL-3

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.

auto_awesome What this module does

AI-generated from the code · Odoo 16.0

This module lets developers define simple data models inside Odoo that can be converted to and from JSON. It is a technical foundation for building REST APIs and data exchanges, not a screen-based feature for end users.

This module adds a technical layer that lets developers declare lightweight data models directly in Odoo code. These models are not database tables; they are used to describe the shape of data that is sent or received, for example in JSON format.

  • A builder runs automatically when Odoo loads, scanning installed modules and registering every declared data model in a global registry.
  • Data models support inheritance similar to Odoo models: a model can extend an existing one or create a new one based on another.
  • Validation and conversion to/from JSON are handled through schemas, including nested data models.
  • A special nested field type lets one data model contain another, and it resolves the nested model automatically.
  • The environment is attached to each data model so it can access Odoo data when needed.

There are no menus, buttons, or reports. The module touches the datamodel.builder abstract model and the base data model, and it extends the Odoo environment with a datamodels accessor. It depends on the Python libraries marshmallow and marshmallow-objects. Because it is a developer tool, business users will not see direct changes in the interface; it is meant to be used by other modules that need structured data handling.

Required by other modules

Models and fields (2)
  • base · new model
  • datamodel.builder · new model

Text generated by AI (DeepSeek) from reading the Odoo 16.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 5 confirmed, 4 with no information of 9 versions.

Sources · Odoo 13.0

Confirmed on 2026-11-03 in branch 13.0 of OCA/rest-framework.

terminal Installation and usage

OCA documentation · Odoo 16.0

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([])

The env property into a Datamodel instance is mutable. IOW, you can't rely on information (context, user) provided by the environment. The env property is a helper property that give you access to the odoo's registry and must be use with caution.

No verified information in OCA: Installation, Configuration.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.