From 46b7fb598498dfe8673268e82944488b741f5caa Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 2 Apr 2020 13:11:51 +0000 Subject: [PATCH] [FIX] core: do not register classes when `_module` is falsy The goal is to avoid a class from being added in the dictionary `MetaModel.module_to_models`. We use this feature in tests to prevent classes extending models from triggering bugs when reloading the registry (for whatever reason). X-original-commit: 12db61b787b2035bf0c1f2a68a24449d484744c8 --- odoo/addons/test_new_api/tests/test_new_fields.py | 4 ++++ odoo/models.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index ee89c51ab8d..97d1cb2dacc 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -2615,6 +2615,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase): def test_ondelete_unexisting_policy(self): class Foo(models.Model): + _module = None _inherit = self.MODEL_REQUIRED my_selection = fields.Selection(selection_add=[ @@ -2628,6 +2629,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase): def test_ondelete_default_no_default(self): class Foo(models.Model): + _module = None _inherit = self.MODEL_BASE my_selection = fields.Selection(selection_add=[ @@ -2641,6 +2643,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase): def test_ondelete_required_null_explicit(self): class Foo(models.Model): + _module = None _inherit = self.MODEL_REQUIRED my_selection = fields.Selection(selection_add=[ @@ -2654,6 +2657,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase): def test_ondelete_required_null_implicit(self): class Foo(models.Model): + _module = None _inherit = self.MODEL_REQUIRED my_selection = fields.Selection(selection_add=[ diff --git a/odoo/models.py b/odoo/models.py index 8a46be32f1f..ee8bf814211 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -161,7 +161,7 @@ class MetaModel(api.Meta): self._module = self._get_addon_name(self.__module__) # Remember which models to instanciate for this module. - if not self._custom: + if self._module: self.module_to_models[self._module].append(self) # check for new-api conversion error: leave comma after field definition