summaryrefslogtreecommitdiff
path: root/odoo/modules/registry.py
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/modules/registry.py')
-rw-r--r--odoo/modules/registry.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py
index aba103ffcfd..8de7172ae89 100644
--- a/odoo/modules/registry.py
+++ b/odoo/modules/registry.py
@@ -4,16 +4,17 @@
""" Models registries.
"""
-from collections import Mapping, defaultdict
+from collections import Mapping, defaultdict, deque
from contextlib import closing
+from operator import attrgetter
import logging
import os
import threading
import odoo
from .. import SUPERUSER_ID
-from odoo.tools import assertion_report, lazy_classproperty, config, \
- lazy_property, topological_sort, OrderedSet
+from odoo.tools import (assertion_report, lazy_classproperty, config,
+ lazy_property, topological_sort, OrderedSet)
from odoo.tools.lru import LRU
_logger = logging.getLogger(__name__)
@@ -222,6 +223,22 @@ class Registry(Mapping):
env[model_name]._parent_store_compute()
self._init = False
+ def descendants(self, model_names, *kinds):
+ """ Return the models corresponding to ``model_names`` and all those
+ that inherit/inherits from them.
+ """
+ assert all(kind in ('_inherit', '_inherits') for kind in kinds)
+ funcs = [attrgetter(kind + '_children') for kind in kinds]
+
+ models = OrderedSet()
+ queue = deque(model_names)
+ while queue:
+ model = self[queue.popleft()]
+ models.add(model)
+ for func in funcs:
+ queue.extend(func(model))
+ return models
+
def load(self, cr, module):
""" Load a given module in the registry, and return the names of the
modified models.
@@ -234,23 +251,17 @@ class Registry(Mapping):
"""
from .. import models
- loaded_models = OrderedSet()
- def mark_loaded(model):
- # recursively mark model and its children
- loaded_models.add(model._name)
- for child_name in model._inherit_children:
- mark_loaded(self[child_name])
-
lazy_property.reset_all(self)
# Instantiate registered classes (via the MetaModel automatic discovery
# or via explicit constructor call), and add them to the pool.
+ model_names = []
for cls in models.MetaModel.module_to_models.get(module.name, []):
# models register themselves in self.models
model = cls._build_model(self, cr)
- mark_loaded(model)
+ model_names.append(model._name)
- return list(loaded_models)
+ return self.descendants(model_names, '_inherit')
def setup_models(self, cr, partial=False):
""" Complete the setup of models.