From 788ed4e5ddfcb616dcfb8b4819a2bc99a4e7c02d Mon Sep 17 00:00:00 2001 From: Emanuele Date: Mon, 27 Oct 2025 14:52:16 +0100 Subject: [PATCH 1/2] [IMP] orm: add warning about model extension When a model is defined with `_inherit` using a list, Odoo will do a check with the class name to set the `_name` of the model being extended. This is different than the previous versions and can be misleading --- content/developer/reference/backend/orm.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/developer/reference/backend/orm.rst b/content/developer/reference/backend/orm.rst index ae88e09206..04052ad636 100644 --- a/content/developer/reference/backend/orm.rst +++ b/content/developer/reference/backend/orm.rst @@ -1249,6 +1249,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:: From 6a5aacf2576b4b457e9c1a2b29e6cbd038480b1d Mon Sep 17 00:00:00 2001 From: "Emanuele (emi)" <70145331+emi-odoo@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:14:27 +0200 Subject: [PATCH 2/2] [FIX] orm: adapt indentation of python examples This commit fixes the current indentation of python blocks, as they're not valid. --- content/developer/reference/backend/orm.rst | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/content/developer/reference/backend/orm.rst b/content/developer/reference/backend/orm.rst index 04052ad636..8bb260b777 100644 --- a/content/developer/reference/backend/orm.rst +++ b/content/developer/reference/backend/orm.rst @@ -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 @@ -1270,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' @@ -1338,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)