Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions content/developer/reference/backend/orm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1227,18 +1227,20 @@ When using :attr:`~odoo.models.Model._inherit` but leaving out
:attr:`~odoo.models.Model._name`, the new model replaces the existing one,
essentially extending it in-place. This is useful to add new fields or methods
to existing models (created in other modules), or to customize or reconfigure
them (e.g. to change their default sort order)::
them (e.g. to change their default sort order)

.. code-block:: python

class Extension0(models.Model):
_name = 'extension.0'
_description = 'Extension zero'
_name = 'extension.0'
_description = 'Extension zero'

name = fields.Char(default="A")
name = fields.Char(default="A")

class Extension0(models.Model):
_inherit = ['extension.0']
_inherit = 'extension.0'

description = fields.Char(default="Extended")
description = fields.Char(default="Extended")

.. code-block:: python3

Expand All @@ -1249,6 +1251,9 @@ will yield::

{'name': "A", 'description': "Extended"}

.. warning:: When :attr:`~odoo.models.Model._inherit` is set to a string,
then :attr:`~odoo.models.Model._name` is set to the same value,
unless `_name` is explicitly set.

.. note::

Expand All @@ -1267,7 +1272,9 @@ model.

The main difference is in the meaning. When using Delegation, the model
**has one** instead of **is one**, turning the relationship in a composition
instead of inheritance::
instead of inheritance

.. code-block:: python

class Screen(models.Model):
_name = 'delegation.screen'
Expand Down Expand Up @@ -1335,7 +1342,9 @@ In that case, the attributes of the field are taken from the parent class
and overridden by the ones given in subclasses.

For instance, the second class below only adds a tooltip on the field
``state``::
``state``

.. code-block:: python

class FirstFoo(models.Model):
state = fields.Selection([...], required=True)
Expand Down