def upgrade_database(self, cr, uid, obj, context=None): res = {} scheme = request.httprequest.scheme payload = { 'update_addons': obj.update_addons, 'install_addons': obj.install_addons, 'uninstall_addons': obj.uninstall_addons, 'fixes': ','.join(['%s-%s' % (x.model, x.method) for x in obj.fix_ids]) } dbs = obj.database and obj.database.split(',') or database.get_market_dbs(False) for db in dbs: url = '{scheme}://{domain}/saas_client/upgrade_database'.format(scheme=scheme, domain=db.replace('_', '.')) r = requests.post(url, data=payload) res[db] = r.status_code self.write(cr, uid, obj.id, {'description': str(res)}) return { 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'saas.config', 'res_id': obj.id, 'target': 'new' }
def upgrade_database(self, cr, uid, obj, context=None): res = {} scheme = request.httprequest.scheme payload = { 'update_addons': obj.update_addons, 'install_addons': obj.install_addons, 'uninstall_addons': obj.uninstall_addons, 'fixes': ','.join(['%s-%s' % (x.model, x.method) for x in obj.fix_ids]) } dbs = obj.database and obj.database.split( ',') or database.get_market_dbs(False) for db in dbs: url = '{scheme}://{domain}/saas_client/upgrade_database'.format( scheme=scheme, domain=db.replace('_', '.')) r = requests.post(url, data=payload) res[db] = r.status_code self.write(cr, uid, obj.id, {'description': str(res)}) return { 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'saas.config', 'res_id': obj.id, 'target': 'new' }
def synchronize_objects(self): flow = self.env['cenit.flow'] dbs = self.database and [self.database] or database.get_market_dbs() for db in dbs: ctx = {'partner_db': db, 'send_method':'local_post'} for x in self.model_ids: domain = [ ('data_type.model.model', '=', x.model) #('purpose', '=', 'send') ] flows = flow.with_context(ctx).search(domain) if flows: flow_ids = [x.id for x in flows] ctx.update({'user': 1}) self.env['cenit.flow'].with_context(ctx).send_all(flow_ids[0])
def upgrade_database(self, cr, uid, obj, context=None): dbs = obj.database and [obj.database] or database.get_market_dbs() uaddons = obj.update_addons and obj.update_addons.split(',') or [] update_domain = [('name', 'in', uaddons)] iaddons = obj.install_addons and obj.install_addons.split(',') or [] install_domain = [('name', 'in', iaddons)] no_update_dbs = [] for db_name in dbs: try: registry = openerp.modules.registry.RegistryManager.get( db_name) with registry.cursor() as rcr: # update database.uuid openerp.service.db._drop_conn(rcr, db_name) module = registry['ir.module.module'] # 1. Update existing modules uaids = module.search(rcr, SUPERUSER_ID, update_domain) if uaids: module.button_upgrade(rcr, SUPERUSER_ID, uaids) # 2. Install new modules iaids = module.search(rcr, SUPERUSER_ID, install_domain) if iaids: module.button_immediate_install( rcr, SUPERUSER_ID, iaids) # 3. Execute methods for fix in obj.fix_ids: getattr(registry[fix.model], fix.method)(rcr, SUPERUSER_ID) except: no_update_dbs.append(db_name) if no_update_dbs: desc = 'These databases were not updated: %s', ', '.join( no_update_dbs) self.write(cr, uid, obj.id, {'description': desc}) return { 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'saas.config', 'res_id': obj.id, 'target': 'new', }
def update_all(self, cr, uid, server_db): db_list = database.get_market_dbs(with_templates=False) _logger.info("Bases de datos: %s", str(db_list)) try: client_list.remove(server_db) except: pass res = [] for db in db_list: registry = openerp.modules.registry.RegistryManager.get(db) with registry.cursor() as db_cr: client_id = registry['ir.config_parameter'].get_param(db_cr, SUPERUSER_ID, 'database.uuid') users = registry['res.users'].search(db_cr, SUPERUSER_ID, [('share', '=', False)]) users_len = len(users) data_dir = openerp.tools.config['data_dir'] file_storage = get_size('%s/filestore/%s' % (data_dir, db)) file_storage = int(file_storage / (1024 * 1024)) db_cr.execute("select pg_database_size('%s')" % db) db_storage = db_cr.fetchone()[0] db_storage = int(db_storage / (1024 * 1024)) data = { 'name': db, 'client_id': client_id, 'users_len': users_len, 'file_storage': file_storage, 'db_storage': db_storage, } oid = self.search(cr, uid, [('client_id', '=', client_id)]) if not oid: self.create(cr, uid, data) else: self.write(cr, uid, oid, data) res.append(data) return res
def update_all(self, cr, uid, server_db): db_list = database.get_market_dbs(with_templates=False) _logger.info("Bases de datos: %s", str(db_list)) try: client_list.remove(server_db) except: pass res = [] for db in db_list: registry = openerp.modules.registry.RegistryManager.get(db) with registry.cursor() as db_cr: client_id = registry['ir.config_parameter'].get_param( db_cr, SUPERUSER_ID, 'database.uuid') users = registry['res.users'].search(db_cr, SUPERUSER_ID, [('share', '=', False)]) users_len = len(users) data_dir = openerp.tools.config['data_dir'] file_storage = get_size('%s/filestore/%s' % (data_dir, db)) file_storage = int(file_storage / (1024 * 1024)) db_cr.execute("select pg_database_size('%s')" % db) db_storage = db_cr.fetchone()[0] db_storage = int(db_storage / (1024 * 1024)) data = { 'name': db, 'client_id': client_id, 'users_len': users_len, 'file_storage': file_storage, 'db_storage': db_storage, } oid = self.search(cr, uid, [('client_id', '=', client_id)]) if not oid: self.create(cr, uid, data) else: self.write(cr, uid, oid, data) res.append(data) return res
def upgrade_database(self, cr, uid, obj, context=None): dbs = obj.database and [obj.database] or database.get_market_dbs() uaddons = obj.update_addons and obj.update_addons.split(',') or [] update_domain = [('name', 'in', uaddons)] iaddons = obj.install_addons and obj.install_addons.split(',') or [] install_domain = [('name', 'in', iaddons)] no_update_dbs = [] for db_name in dbs: try: registry = openerp.modules.registry.RegistryManager.get(db_name) with registry.cursor() as rcr: # update database.uuid openerp.service.db._drop_conn(rcr, db_name) module = registry['ir.module.module'] # 1. Update existing modules uaids = module.search(rcr, SUPERUSER_ID, update_domain) if uaids: module.button_upgrade(rcr, SUPERUSER_ID, uaids) # 2. Install new modules iaids = module.search(rcr, SUPERUSER_ID, install_domain) if iaids: module.button_immediate_install(rcr, SUPERUSER_ID, iaids) # 3. Execute methods for fix in obj.fix_ids: getattr(registry[fix.model], fix.method)(rcr, SUPERUSER_ID) except: no_update_dbs.append(db_name) if no_update_dbs: desc = 'These databases were not updated: %s', ', '.join(no_update_dbs) self.write(cr, uid, obj.id, {'description': desc}) return { 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'saas.config', 'res_id': obj.id, 'target': 'new', }