Пример #1
0
    def _install_modules(self, db_name, modules):
        if self.type != 'local':
            raise NotImplementedError()

        db = sql_db.db_connect(db_name)
        with api.Environment.manage(), db.cursor() as cr:
            env = api.Environment(cr, SUPERUSER_ID, {})

            # Set odoo.http.request to None.
            #
            # Odoo tries to use its values in translation system, which may eventually
            # change currentThread().dbname to saas master value.
            _request_stack.push(None)

            module_ids = env['ir.module.module'].search([('state', '=',
                                                          'uninstalled')] +
                                                        modules)
            with turn_off_tests():
                module_ids.button_immediate_install()

            # Some magic to force reloading registry in other workers
            env.registry.registry_invalidated = True
            env.registry.signal_changes()

            # return request back
            _request_stack.pop()
Пример #2
0
 def assert_modules_is_installed(self, db_name, module):
     db = odoo.sql_db.db_connect(db_name)
     odoo.registry(db_name).check_signaling()
     with odoo.api.Environment.manage(), db.cursor() as cr:
         env = odoo.api.Environment(cr, SUPERUSER_ID, {})
         self.assertTrue(env['ir.module.module'].search([('name', '=',
                                                          module)]))
Пример #3
0
    def install_modules(self, template_id, template_operator_id):
        self.ensure_one()
        modules = [module.name for module in template_id.template_module_ids]
        modules = [('name', 'in', MANDATORY_MODULES + modules)]
        if self.type == 'local':
            db = sql_db.db_connect(template_operator_id.operator_db_name)
            with api.Environment.manage(), db.cursor() as cr:
                env = api.Environment(cr, SUPERUSER_ID, {})

                # Set odoo.http.request to None.
                #
                # Odoo tries to use its values in translation system, which may eventually
                # change currentThread().dbname to saas master value.
                _request_stack.push(None)

                module_ids = env['ir.module.module'].search([('state', '=',
                                                              'uninstalled')] +
                                                            modules)
                module_ids.button_immediate_install()

                # Some magic to force reloading registry in other workers
                env.registry.registry_invalidated = True
                env.registry.signal_changes()

                # return request back
                _request_stack.pop()

            template_operator_id.state = 'post_init'
            self.with_delay().post_init(template_id, template_operator_id)
Пример #4
0
 def update_mod(self):
     module_names = [x.name for x in self.apps]
     db = odoo.sql_db.db_connect(self.name)
     with closing(db.cursor()) as cr:
         env = api.Environment(cr, SUPERUSER_ID, {})
         action = env['ir.actions.act_window'].search([
             ('id', '=', env.ref('my_control_panel.apps_action').id)
         ])
         action.domain = [('name', 'in', module_names)]
         cr.commit()
Пример #5
0
 def install_modulo_lista(self, modulos):
     #self.ensure_one()
     #modules = [module.name for module in self.template_module_ids]
     self.state = 'installing_modules'
     modulos = [('name', 'in', modulos)]
     db = sql_db.db_connect(self.name)
     with api.Environment.manage(), db.cursor() as cr:
         env = api.Environment(cr, SUPERUSER_ID, {})
         module_ids = env['ir.module.module'].search([('state', '=',
                                                       'uninstalled')] +
                                                     modulos)
         module_ids.button_immediate_install()
Пример #6
0
    def install_modules(self, db_name, modules):
        db = sql_db.db_connect(db_name)
        with api.Environment.manage(), db.cursor() as cr:
            env = api.Environment(cr, SUPERUSER_ID, {})

            module_ids = env["ir.module.module"].search([("state", "=",
                                                          "uninstalled")] +
                                                        modules)
            module_ids.button_immediate_install()

            # Some magic to force reloading registry in other workers
            env.registry.registry_invalidated = True
            env.registry.signal_changes()
Пример #7
0
 def install_modulo2(self):
     self.ensure_one()
     #modules = [module.name for module in self.template_module_ids]
     #modules = [('name', 'in', MANDATORY_MODULES + modules)]
     modules = [module.name for module in self.modulos]
     modules = [('name', 'in', MANDATORY_MODULES + modules)]
     db = sql_db.db_connect(self.name)
     with api.Environment.manage(), db.cursor() as cr:
         env = api.Environment(cr, SUPERUSER_ID, {})
         module_ids = env['ir.module.module'].search([('state', '=',
                                                       'uninstalled')] +
                                                     modules)
         module_ids.button_immediate_install()
Пример #8
0
 def post_init(self, template_id, template_operator_id):
     if self.type == 'local':
         db = sql_db.db_connect(template_operator_id.operator_db_name)
         registry(template_operator_id.operator_db_name).check_signaling()
         with api.Environment.manage(), db.cursor() as cr:
             env = api.Environment(cr, SUPERUSER_ID, {})
             action = env['ir.actions.server'].create({
                 'name': 'Local Code Eval',
                 'state': 'code',
                 'model_id': 1,
                 'code': template_id.template_post_init
             })
             action.run()
         template_operator_id.state = 'done'
Пример #9
0
 def install_modules(self, template_id, template_operator_id):
     self.ensure_one()
     modules = [module.name for module in template_id.template_module_ids]
     modules = [('name', 'in', MANDATORY_MODULES + modules)]
     if self.type == 'local':
         db = sql_db.db_connect(template_operator_id.operator_db_name)
         with api.Environment.manage(), db.cursor() as cr:
             env = api.Environment(cr, SUPERUSER_ID, {})
             module_ids = env['ir.module.module'].search([('state', '=', 'uninstalled')] + modules)
             module_ids.button_immediate_install()
             # Some magic to force reloading registry in other workers
             env.registry.registry_invalidated = True
             env.registry.signal_changes()
             template_operator_id.state = 'post_init'
             self.with_delay().post_init(template_id, template_operator_id)
Пример #10
0
 def update_usr(self):
     db = odoo.sql_db.db_connect(self.name)
     with closing(db.cursor()) as cr:
         env = api.Environment(cr, SUPERUSER_ID, {})
         Users = env['res.users']
         for rec in self.users:
             Users.create({
                 'name': rec.name,
                 'login': rec.email,
                 'password': '******',
                 'lang': rec.lang,
                 'image': rec.image,
             })
         self.create_groups(env)
         cr.commit()
Пример #11
0
    def _post_init(self, db_name, template_post_init):
        if self.type != 'local':
            raise NotImplementedError()

        db = sql_db.db_connect(db_name)
        registry(db_name).check_signaling()
        with api.Environment.manage(), db.cursor() as cr:
            env = api.Environment(cr, SUPERUSER_ID, {})
            action = env['ir.actions.server'].create({
                'name': 'Local Code Eval',
                'state': 'code',
                'model_id': 1,
                'code': template_post_init
            })
            action.run()
Пример #12
0
 def post_init(self, db_name, template_post_init):
     db = sql_db.db_connect(db_name)
     registry(db_name).check_signaling()
     with api.Environment.manage(), db.cursor() as cr:
         env = api.Environment(cr, SUPERUSER_ID, {})
         action = env["ir.actions.server"].create({
             "name":
             "Local Code Eval",
             "state":
             "code",
             "model_id":
             1,
             "code":
             template_post_init,
         })
         action.run()
Пример #13
0
 def inits(self):
     # check if valid database name
     if not re.match(DBNAME_PATTERN, self.name):
         raise Exception(
             _('Invalid database name. Only alphanumerical characters, underscore, hyphen and dot are allowed.'
               ))
     # check if db already exit
     if self.name in http.db_list():
         raise ValidationError(
             _('The database: %s already exist.' % (self.name)))
     # check if module assign
     if not self.apps:
         raise ValidationError(
             _('You should have to assign alteast one app to database.'))
     # check if user assign
     if not self.users:
         raise ValidationError(
             _('You should have to assign alteast one user to database.'))
     # check if admin user assign
     if not self.users:
         raise ValidationError(
             _('You should have to assign alteast one admin user to database.'
               ))
     # check all users have email assign
     for rec in self.users:
         if not rec.email:
             raise ValidationError(
                 _('User : %s has no email assign.' % (rec.name)))
     # check if multi users assign same email
     users = [(x.email, ) for x in self.users]
     dup = [x for x in users if users.count(x) > 1]
     if len(dup) > 1:
         raise ValidationError(
             _('Emial : %s assign to muliple users please check.' %
               (dup[0])))
     # check if user already exist on any other database
     for db_name in http.db_list():
         db = odoo.sql_db.db_connect(db_name)
         with closing(db.cursor()) as cr:
             cr.execute('SELECT login FROM res_users ORDER BY login')
             rec = cr.fetchall()
             dup = list(set(users).intersection(rec))
             if len(dup) > 0:
                 raise ValidationError(
                     _('Emial : %s already exist PLEASE CHANGE' % (dup[0])))
     self.write({'state': 'auth'})
Пример #14
0
 def assert_record_is_created(self, db_name, model_name, search_domain):
     db = odoo.sql_db.db_connect(db_name)
     odoo.registry(db_name).check_signaling()
     with odoo.api.Environment.manage(), db.cursor() as cr:
         env = odoo.api.Environment(cr, SUPERUSER_ID, {})
         return self.assertTrue(env[model_name].search(search_domain))