Пример #1
0
    def load(self, cr, module):
        """ Load a given module in the registry.

        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

        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.
        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)

        return map(self, loaded_models)
Пример #2
0
    def setup_models(self, cr, partial=False):
        """ Complete the setup of models.
            This must be called after loading modules and before using the ORM.

            :param partial: ``True`` if all models have not been loaded yet.
        """
        lazy_property.reset_all(self)

        # load custom models
        ir_model = self['ir.model']
        cr.execute('SELECT * FROM ir_model WHERE state=%s', ('manual', ))
        for model_data in cr.dictfetchall():
            ir_model._instanciate(cr, SUPERUSER_ID, model_data, {})

        # prepare the setup on all models
        for model in self.models.itervalues():
            model._prepare_setup(cr, SUPERUSER_ID)

        # do the actual setup from a clean state
        self._m2m = {}
        for model in self.models.itervalues():
            model._setup_base(cr, SUPERUSER_ID, partial)

        for model in self.models.itervalues():
            model._setup_fields(cr, SUPERUSER_ID)

        for model in self.models.itervalues():
            model._setup_complete(cr, SUPERUSER_ID)
Пример #3
0
    def setup_models(self, cr, partial=False):
        """ Complete the setup of models.
            This must be called after loading modules and before using the ORM.

            :param partial: ``True`` if all models have not been loaded yet.
        """
        lazy_property.reset_all(self)
        env = openerp.api.Environment(cr, SUPERUSER_ID, {})

        # load custom models
        ir_model = env['ir.model']
        cr.execute('SELECT * FROM ir_model WHERE state=%s', ('manual', ))
        for model_data in cr.dictfetchall():
            ir_model._instanciate(model_data)

        # prepare the setup on all models
        models = [env[model_name] for model_name in self.models]
        for model in models:
            model._prepare_setup()

        # do the actual setup from a clean state
        self._m2m = {}
        for model in models:
            model._setup_base(partial)

        for model in models:
            model._setup_fields(partial)

        for model in models:
            model._setup_complete()
Пример #4
0
    def setup_models(self, cr, partial=False):
        """ Complete the setup of models.
            This must be called after loading modules and before using the ORM.

            :param partial: ``True`` if all models have not been loaded yet.
        """
        lazy_property.reset_all(self)

        # load custom models
        ir_model = self['ir.model']
        cr.execute('select model, transient from ir_model where state=%s', ('manual',))
        for (model_name, transient) in cr.fetchall():
            ir_model.instanciate(cr, SUPERUSER_ID, model_name, transient, {})

        # prepare the setup on all models
        for model in self.models.itervalues():
            model._prepare_setup(cr, SUPERUSER_ID)

        # do the actual setup from a clean state
        self._m2m = {}
        for model in self.models.itervalues():
            model._setup_base(cr, SUPERUSER_ID, partial)

        for model in self.models.itervalues():
            model._setup_fields(cr, SUPERUSER_ID)

        for model in self.models.itervalues():
            model._setup_complete(cr, SUPERUSER_ID)
Пример #5
0
    def load(self, cr, module):
        """ Load a given module in the registry.

        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

        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.
        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)

        return map(self, loaded_models)
Пример #6
0
    def load(self, cr, module):
        """ Load a given module in the registry.

        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.

        """
        models_to_load = []  # need to preserve loading order
        lazy_property.reset_all(self)

        # call hook before adding stuff in the registry
        for model in self.models.itervalues():
            model._before_registry_update(cr, SUPERUSER_ID)

        # Instantiate registered classes (via the MetaModel automatic discovery
        # or via explicit constructor call), and add them to the pool.
        for cls in openerp.osv.orm.MetaModel.module_to_models.get(
                module.name, []):
            # models register themselves in self.models
            model = cls._build_model(self, cr)
            if model._name not in models_to_load:
                # avoid double-loading models whose declaration is split
                models_to_load.append(model._name)

        # call hook after models have been instantiated
        for model in self.models.itervalues():
            model._after_registry_update(cr, SUPERUSER_ID)

        return [self.models[m] for m in models_to_load]
Пример #7
0
    def setup_models(self, cr, partial=False):
        """ Complete the setup of models.
            This must be called after loading modules and before using the ORM.

            :param partial: ``True`` if all models have not been loaded yet.
        """
        lazy_property.reset_all(self)
        env = openerp.api.Environment(cr, SUPERUSER_ID, {})

        # load custom models
        ir_model = env['ir.model']
        cr.execute('SELECT * FROM ir_model WHERE state=%s', ('manual',))
        for model_data in cr.dictfetchall():
            ir_model._instanciate(model_data)

        # prepare the setup on all models
        models = 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(partial)

        for model in models:
            model._setup_fields(partial)

        for model in models:
            model._setup_complete()
Пример #8
0
    def load(self, cr, module):
        """ Load a given module in the registry.

        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.

        """
        models_to_load = [] # need to preserve loading order
        lazy_property.reset_all(self)

        # call hook before adding stuff in the registry
        for model in self.models.itervalues():
            model._before_registry_update(cr, SUPERUSER_ID)

        # Instantiate registered classes (via the MetaModel automatic discovery
        # or via explicit constructor call), and add them to the pool.
        for cls in openerp.osv.orm.MetaModel.module_to_models.get(module.name, []):
            # models register themselves in self.models
            model = cls._build_model(self, cr)
            if model._name not in models_to_load:
                # avoid double-loading models whose declaration is split
                models_to_load.append(model._name)

        # call hook after models have been instantiated
        for model in self.models.itervalues():
            model._after_registry_update(cr, SUPERUSER_ID)

        return [self.models[m] for m in models_to_load]
Пример #9
0
    def load(self, cr, module):
        """ Load a given module in the registry.

        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

        models_to_load = [] # need to preserve loading order
        lazy_property.reset_all(self)

        # Instantiate registered classes (via the MetaModel automatic discovery
        # or via explicit constructor call), and add them to the pool.
        for cls in models.MetaModel.module_to_models.get(module.name, []):
            # models register themselves in self.models
            model = cls._build_model(self, cr)
            if model._name not in models_to_load:
                # avoid double-loading models whose declaration is split
                models_to_load.append(model._name)

        return [self.models[m] for m in models_to_load]
Пример #10
0
    def load(self, cr, module):
        """ Load a given module in the registry.

        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

        models_to_load = []  # need to preserve loading order
        lazy_property.reset_all(self)

        # Instantiate registered classes (via the MetaModel automatic discovery
        # or via explicit constructor call), and add them to the pool.
        for cls in models.MetaModel.module_to_models.get(module.name, []):
            # models register themselves in self.models
            model = cls._build_model(self, cr)
            if model._name not in models_to_load:
                # avoid double-loading models whose declaration is split
                models_to_load.append(model._name)

        return [self.models[m] for m in models_to_load]