diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-09-22 15:23:45 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-09-22 15:23:45 +0200 |
| commit | 856476d4418390ca89ef161e31faf61248eeaa1d (patch) | |
| tree | f87ab29316440a28e9032d1b811eeb7ea5155653 /odoo/modules | |
| parent | 4b812d9965128b02b4ac5ea49a66da622953cddc (diff) | |
| parent | b1b700adb1f26bb43e8f4b77b85f969a4b52d36c (diff) | |
[MERGE] forward port branch saas-12 up to b1b700a
Diffstat (limited to 'odoo/modules')
| -rw-r--r-- | odoo/modules/registry.py | 35 |
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. |
