[MERGE] forward port branch saas-12 up to b1b700a

This commit is contained in:
Christophe Simonis
2016-09-22 15:23:45 +02:00
32 changed files with 1030 additions and 972 deletions
+23 -12
View File
@@ -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.