From 76eea78a33ba38e987c5753c7fd285440a34af49 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Mon, 27 Oct 2025 13:52:16 +0000 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 X-original-commit: bb65662f04a9c2a182a0471249d2322b1902c2f7 --- 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 dd8d5070673076f1c9e7f0372cd56d13a813d5f5 Mon Sep 17 00:00:00 2001 From: "Emanuele (emi)" <70145331+emi-odoo@users.noreply.github.com> Date: Thu, 23 Oct 2025 08:14:27 +0000 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. X-original-commit: 0afc64eb258f89cfcfdcca1529db0864b3108fef --- 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)