def load(self, cr, module): """ Load a given module in the registry, and return the names of the modified models. At the Python level, the modules are already loaded, but not yet on a per-registry level. This method populates a registry with the given modules, i.e. it instanciates all the classes of a the given module and registers them in the registry. """ from .. import models # clear cache to ensure consistency, but do not signal it self.__cache.clear() 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) model_names.append(model._name) return self.descendants(model_names, '_inherit', '_inherits')
def setup_models(self, cr): """ Complete the setup of models. This must be called after loading modules and before using the ORM. """ lazy_property.reset_all(self) env = flectra.api.Environment(cr, SUPERUSER_ID, {}) # add manual models if self._init_modules: env['ir.model']._add_manual_models() # prepare the setup on all models models = list(env.values()) for model in models: model._prepare_setup() # do the actual setup from a clean state self._m2m = {} for model in models: model._setup_base() for model in models: model._setup_fields() for model in models: model._setup_complete() self.registry_invalidated = True
def setup_models(self, cr): """ Complete the setup of models. This must be called after loading modules and before using the ORM. """ env = flectra.api.Environment(cr, SUPERUSER_ID, {}) # Uninstall registry hooks. Because of the condition, this only happens # on a fully loaded registry, and not on a registry being loaded. if self.ready: for model in env.values(): model._unregister_hook() # clear cache to ensure consistency, but do not signal it self.__cache.clear() lazy_property.reset_all(self) self.registry_invalidated = True if env.all.tocompute: _logger.error( "Remaining fields to compute before setting up registry: %s", env.all.tocompute, stack_info=True, ) # add manual models if self._init_modules: env['ir.model']._add_manual_models() # prepare the setup on all models models = list(env.values()) for model in models: model._prepare_setup() # do the actual setup from a clean state self._m2m = defaultdict(list) for model in models: model._setup_base() for model in models: model._setup_fields() for model in models: model._setup_complete() # Reinstall registry hooks. Because of the condition, this only happens # on a fully loaded registry, and not on a registry being loaded. if self.ready: for model in env.values(): model._register_hook() env['base'].flush()