addons14/datamodel/core.py
def _build_datamodel(cls, registry):
        """Instantiate a given Datamodel in the datamodels registry.

        This method is called at the end of the Odoo's registry build.  The
        caller is :meth:`datamodel.builder.DatamodelBuilder.load_datamodels`.

        It generates new classes, which will be the Datamodel classes we will
        be using.  The new classes are generated following the inheritance
        of ``_inherit``. It ensures that the ``__bases__`` of the generated
        Datamodel classes follow the ``_inherit`` chain.

        Once a Datamodel class is created, it adds it in the Datamodel Registry
        (:class:`DatamodelRegistry`), so it will be available for
        lookups.

        At the end of new class creation, a hook method
        :meth:`_complete_datamodel_build` is called, so you can customize
        further the created datamodels.

        The following code is roughly the same than the Odoo's one for
        building Models.

        """

        # In the simplest case, the datamodel's registry class inherits from
        # cls and the other classes that define the datamodel in a flat
        # hierarchy.  The registry contains the instance ``datamodel`` (on the
        # left). Its class, ``DatamodelClass``, carries inferred metadata that
        # is shared between all the datamodel's instances for this registry
        # only.
        #
        #   class A1(Datamodel):                    Datamodel
        #       _name = 'a'                           / | \
        #                                            A3 A2 A1
        #   class A2(Datamodel):                      \ | /
        #       _inherit = 'a'                    DatamodelClass
        #
        #   class A3(Datamodel):
        #       _inherit = 'a'
        #
        # When a datamodel is extended by '_inherit', its base classes are
        # modified to include the current class and the other inherited
        # datamodel classes.
        # Note that we actually inherit from other ``DatamodelClass``, so that
        # extensions to an inherited datamodel are immediately visible in the
        # current datamodel class, like in the following example:
        #
        #   class A1(Datamodel):
        #       _name = 'a'                          Datamodel
        #                                            /  / \  \
        #   class B1(Datamodel):                    /  A2 A1  \
        #       _name = 'b'                        /   \  /    \
        #                                         B2 DatamodelA B1
        #   class B2(Datamodel):                   \     |     /
        #       _name = 'b'                         \    |    /
        #       _inherit = ['b', 'a']                \   |   /
        #                                            DatamodelB
        #   class A2(Datamodel):
        #       _inherit = 'a'

        # determine inherited datamodels
        parents = cls._inherit
        if isinstance(parents, str):
            parents = [parents]
        elif parents is None:
            parents = []

        if cls._name in registry and not parents:
            raise TypeError(
                "Datamodel %r (in class %r) already exists. "
                "Consider using _inherit instead of _name "
                "or using a different _name." % (cls._name, cls)
            )

        # determine the datamodel's name
        name = cls._name or (len(parents) == 1 and parents[0])

        if not name:
            raise TypeError("Datamodel %r must have a _name" % cls)

        # all datamodels except 'base' implicitly inherit from 'base'
        if name != "base":
            parents = list(parents) + ["base"]

        # create or retrieve the datamodel's class
        if name in parents:
            if name not in registry:
                raise TypeError("Datamodel %r does not exist in registry." % name)

        # determine all the classes the datamodel should inherit from
        bases = LastOrderedSet([cls])
        for parent in parents:
            if parent not in registry:
                raise TypeError(
                    "Datamodel %r inherits from non-existing datamodel %r."
                    % (name, parent)
                )
            parent_class = registry[parent]
            if parent == name:
                for base in parent_class.__bases__:
                    bases.add(base)
            else:
                bases.add(parent_class)
                parent_class._inherit_children.add(name)

        if name in parents:
            DatamodelClass = registry[name]
            # Add the new bases to the existing model since the class into
            # the registry could already be used into an inherit
            DatamodelClass.__bases__ = tuple(bases)
            # We must update the marshmallow schema on the existing datamodel
            # class to include those inherited
            parent_schemas = []
            for parent in bases:
                if issubclass(parent, MarshmallowModel):
                    parent_schemas.append(parent.__schema_class__)
            schema_class = type(name + "Schema", tuple(parent_schemas), {})
            DatamodelClass.__schema_class__ = schema_class
        else:
            attrs = {
                "_name": name,
                "_register": False,
                # names of children datamodel
                "_inherit_children": OrderedSet(),
            }
            if name == "base":
                attrs["_registry"] = registry
            DatamodelClass = type(name, tuple(bases), attrs)

        setattr(DatamodelClass.__schema_class__, "_registry", registry)  # noqa: B010
        setattr(DatamodelClass.__schema_class__, "_datamodel_name", name)  # noqa: B010
        setattr(  # noqa: B010
            DatamodelClass.__schema_class__, "__make_object__", __make_object__
        )
        DatamodelClass._complete_datamodel_build()

        registry[name] = DatamodelClass

        return DatamodelClass
Instantiate a given Datamodel in the datamodels registry.

        This method is called at the end of the Odoo's registry build.  The
        caller is :meth:`datamodel.builder.DatamodelBuilder.load_datamodels`.

        It generates new classes, which will be the Datamodel classes we will
        be using.  The new classes are generated following the inheritance
        of ``_inherit``. It ensures that the ``__bases__`` of the generated
        Datamodel classes follow the ``_inherit`` chain.

        Once a Datamodel class is created, it adds it in the Datamodel Registry
        (:class:`DatamodelRegistry`), so it will be available for
        lookups.

        At the end of new class creation, a hook method
        :meth:`_complete_datamodel_build` is called, so you can customize
        further the created datamodels.

        The following code is roughly the same than the Odoo's one for
        building Models.

        
Instantiate a given Datamodel in the datamodels registry.
This method is called at the end of the Odoo's registry build.

It generates new classes, which will be the Datamodel classes we will
be using.  The new classes are generated following the inheritance
of ``_inherit``.

Once a Datamodel class is created, it adds it in the Datamodel Registry
(:class:`DatamodelRegistry`), so it will be available for
lookups.

At the end of new class creation, a hook method
Instantiate a given Datamodel in the datamodels registry . This method is called at the end of the Odoo ' s registry build . It generates new classes which will be the Datamodel classes we will be using . The new classes are generated following the inheritance of ` ` _inherit ` ` . Once a Datamodel class is created it adds it in the Datamodel Registry ( : class : ` DatamodelRegistry ` ) so it will be available for lookups . At the end of new class creation a hook method
def _build_datamodel(cls, registry):
           class A1(Datamodel):                    Datamodel
               _name = 'a'                           / | \
                                                    A3 A2 A1
           class A2(Datamodel):                      \ | /
               _inherit = 'a'                    DatamodelClass
           class A3(Datamodel):
               _inherit = 'a'
         When a datamodel is extended by '_inherit', its base classes are
         modified to include the current class and the other inherited
         datamodel classes.
         Note that we actually inherit from other ``DatamodelClass``, so that
         extensions to an inherited datamodel are immediately visible in the
         current datamodel class, like in the following example:
           class A1(Datamodel):
               _name = 'a'                          Datamodel
                                                    /  / \  \
           class B1(Datamodel):                    /  A2 A1  \
               _name = 'b'                        /   \  /    \
                                                 B2 DatamodelA B1
           class B2(Datamodel):                   \     |     /
               _name = 'b'                         \    |    /
               _inherit = ['b', 'a']                \   |   /
                                                    DatamodelB
           class A2(Datamodel):
               _inherit = 'a'
         determine inherited datamodels
        parents = cls._inherit
        if isinstance(parents, str):
            parents = [parents]
        elif parents is None:
            parents = []
        if cls._name in registry and not parents:
            raise TypeError(
                "Datamodel %r (in class %r) already exists. "
                "Consider using _inherit instead of _name "
                "or using a different _name." % (cls._name, cls)
            )
         determine the datamodel's name
        name = cls._name or (len(parents) == 1 and parents[0])
        if not name:
            raise TypeError("Datamodel %r must have a _name" % cls)
         all datamodels except 'base' implicitly inherit from 'base'
        if name != "base":
            parents = list(parents) + ["base"]
         create or retrieve the datamodel's class
        if name in parents:
            if name not in registry:
                raise TypeError("Datamodel %r does not exist in registry." % name)
         determine all the classes the datamodel should inherit from
        bases = LastOrderedSet([cls])
        for parent in parents:
            if parent not in registry:
                raise TypeError(
                    "Datamodel %r inherits from non-existing datamodel %r."
                    % (name, parent)
                )
            parent_class = registry[parent]
            if parent == name:
                for base in parent_class.__bases__:
                    bases.add(base)
            else:
                bases.add(parent_class)
                parent_class._inherit_children.add(name)
        if name in parents:
            DatamodelClass = registry[name]
             Add the new bases to the existing model since the class into
             the registry could already be used into an inherit
            DatamodelClass.__bases__ = tuple(bases)
             We must update the marshmallow schema on the existing datamodel
             class to include those inherited
            parent_schemas = []
            for parent in bases:
                if issubclass(parent, MarshmallowModel):
                    parent_schemas.append(parent.__schema_class__)
            schema_class = type(name + "Schema", tuple(parent_schemas), {})
            DatamodelClass.__schema_class__ = schema_class
        else:
            attrs = {
                "_name": name,
                "_register": False,
                 names of children datamodel
                "_inherit_children": OrderedSet(),
            }
            if name == "base":
                attrs["_registry"] = registry
            DatamodelClass = type(name, tuple(bases), attrs)
        setattr(DatamodelClass.__schema_class__, "_registry", registry)   noqa: B010
        setattr(DatamodelClass.__schema_class__, "_datamodel_name", name)   noqa: B010
        setattr(   noqa: B010
            DatamodelClass.__schema_class__, "__make_object__", __make_object__
        )
        DatamodelClass._complete_datamodel_build()
        registry[name] = DatamodelClass
        return DatamodelClass
def _build_datamodel ( cls , registry ) : parents = cls . _inherit if isinstance ( parents , str ) : parents = [ parents ] elif parents is None : parents = [ ] if cls . _name in registry and not parents : raise TypeError ( "Datamodel %r (in class %r) already exists. " "Consider using _inherit instead of _name " "or using a different _name." % ( cls . _name , cls ) ) name = cls . _name or ( len ( parents ) == 1 and parents [ 0 ] ) if not name : raise TypeError ( "Datamodel %r must have a _name" % cls ) if name != "base" : parents = list ( parents ) + [ "base" ] if name in parents : if name not in registry : raise TypeError ( "Datamodel %r does not exist in registry." % name ) bases = LastOrderedSet ( [ cls ] ) for parent in parents : if parent not in registry : raise TypeError ( "Datamodel %r inherits from non-existing datamodel %r." % ( name , parent ) ) parent_class = registry [ parent ] if parent == name : for base in parent_class . __bases__ : bases . add ( base ) else : bases . add ( parent_class ) parent_class . _inherit_children . add ( name ) if name in parents : DatamodelClass = registry [ name ] DatamodelClass . __bases__ = tuple ( bases ) parent_schemas = [ ] for parent in bases : if issubclass ( parent , MarshmallowModel ) : parent_schemas . append ( parent . __schema_class__ ) schema_class = type ( name + "Schema" , tuple ( parent_schemas ) , { } ) DatamodelClass . __schema_class__ = schema_class else : attrs = { "_name" : name , "_register" : False , "_inherit_children" : OrderedSet ( ) , } if name == "base" : attrs [ "_registry" ] = registry DatamodelClass = type ( name , tuple ( bases ) , attrs ) setattr ( DatamodelClass . __schema_class__ , "_registry" , registry ) setattr ( DatamodelClass . __schema_class__ , "_datamodel_name" , name ) setattr ( DatamodelClass . __schema_class__ , "__make_object__" , __make_object__ ) DatamodelClass . _complete_datamodel_build ( ) registry [ name ] = DatamodelClass return DatamodelClass
Instantiate a given Datamodel in the datamodels registry.
Instantiate a given Datamodel in the datamodels registry .
"""Instantiate a given Datamodel in the datamodels registry.

        This method is called at the end of the Odoo's registry build.  The
        caller is :meth:`datamodel.builder.DatamodelBuilder.load_datamodels`.

        It generates new classes, which will be the Datamodel classes we will
        be using.  The new classes are generated following the inheritance
        of ``_inherit``. It ensures that the ``__bases__`` of the generated
        Datamodel classes follow the ``_inherit`` chain.

        Once a Datamodel class is created, it adds it in the Datamodel Registry
        (:class:`DatamodelRegistry`), so it will be available for
        lookups.

        At the end of new class creation, a hook method
        :meth:`_complete_datamodel_build` is called, so you can customize
        further the created datamodels.

        The following code is roughly the same than the Odoo's one for
        building Models.

        """ # In the simplest case, the datamodel's registry class inherits from # cls and the other classes that define the datamodel in a flat # hierarchy.  The registry contains the instance ``datamodel`` (on the # left). Its class, ``DatamodelClass``, carries inferred metadata that # is shared between all the datamodel's instances for this registry # only. # #   class A1(Datamodel):                    Datamodel #       _name = 'a'                           / | \ #                                            A3 A2 A1 #   class A2(Datamodel):                      \ | / #       _inherit = 'a'                    DatamodelClass # #   class A3(Datamodel): #       _inherit = 'a' # # When a datamodel is extended by '_inherit', its base classes are # modified to include the current class and the other inherited # datamodel classes. # Note that we actually inherit from other ``DatamodelClass``, so that # extensions to an inherited datamodel are immediately visible in the # current datamodel class, like in the following example: # #   class A1(Datamodel): #       _name = 'a'                          Datamodel #                                            /  / \  \ #   class B1(Datamodel):                    /  A2 A1  \ #       _name = 'b'                        /   \  /    \ #                                         B2 DatamodelA B1 #   class B2(Datamodel):                   \     |     / #       _name = 'b'                         \    |    / #       _inherit = ['b', 'a']                \   |   / #                                            DatamodelB #   class A2(Datamodel): #       _inherit = 'a' # determine inherited datamodels # determine the datamodel's name # all datamodels except 'base' implicitly inherit from 'base' # create or retrieve the datamodel's class # determine all the classes the datamodel should inherit from # Add the new bases to the existing model since the class into # the registry could already be used into an inherit # We must update the marshmallow schema on the existing datamodel # class to include those inherited # names of children datamodel # noqa: B010 # noqa: B010 # noqa: B010
cls
registry
meth
`_complete_datamodel_build` is called, so you can customize
further the created datamodels.

The following code is roughly the same than the Odoo's one for
building Models.
` _complete_datamodel_build ` is called so you can customize further the created datamodels . The following code is roughly the same than the Odoo ' s one for building Models .