def button_install(self): # domain to select auto-installable (but not yet installed) modules auto_domain = [('state', '=', 'uninstalled'), ('auto_install', '=', True)] # determine whether an auto-install module must be installed: # - all its dependencies are installed or to be installed, # - at least one dependency is 'to install' install_states = frozenset(('installed', 'to install', 'to upgrade')) def must_install(module): states = set(dep.state for dep in module.dependencies_id) return states <= install_states and 'to install' in states modules = self while modules: # Mark the given modules and their dependencies to be installed. modules.state_update('to install', ['uninstalled']) # Determine which auto-installable modules must be installed. modules = self.search(auto_domain).filtered(must_install) # retrieve the installed (or to be installed) theme modules theme_category = self.env.ref('base.module_category_theme') theme_modules = self.search([ ('state', 'in', list(install_states)), ('category_id', 'child_of', [theme_category.id]), ]) # determine all theme modules that mods depends on, including mods def theme_deps(mods): deps = mods.mapped('dependencies_id.depend_id') while deps: mods |= deps deps = deps.mapped('dependencies_id.depend_id') return mods & theme_modules if any(module.state == 'to install' for module in theme_modules): # check: the installation is valid if all installed theme modules # correspond to one theme module and all its theme dependencies if not any( theme_deps(module) == theme_modules for module in theme_modules): state_labels = dict( self.fields_get(['state'])['state']['selection']) themes_list = [ "- %s (%s)" % (module.shortdesc, state_labels[module.state]) for module in theme_modules ] raise UserError(_( "You are trying to install incompatible themes:\n%s\n\n" \ "Please uninstall your current theme before installing another one.\n" "Warning: switching themes may significantly alter the look of your current website pages!" ) % ("\n".join(themes_list))) return dict(ACTION_DICT, name=_('Install'))
def button_install(self): # domain to select auto-installable (but not yet installed) modules auto_domain = [('state', '=', 'uninstalled'), ('auto_install', '=', True)] # determine whether an auto-install module must be installed: # - all its dependencies are installed or to be installed, # - at least one dependency is 'to install' install_states = frozenset(('installed', 'to install', 'to upgrade')) def must_install(module): states = set(dep.state for dep in module.dependencies_id) return states <= install_states and 'to install' in states modules = self while modules: # Mark the given modules and their dependencies to be installed. modules.state_update('to install', ['uninstalled']) # Determine which auto-installable modules must be installed. modules = self.search(auto_domain).filtered(must_install) # the modules that are installed/to install/to upgrade install_mods = self.search([('state', 'in', list(install_states))]) # check individual exclusions install_names = {module.name for module in install_mods} for module in install_mods: for exclusion in module.exclusion_ids: if exclusion.name in install_names: msg = _('Modules "%s" and "%s" are incompatible.') raise UserError(msg % (module.shortdesc, exclusion.exclusion_id.shortdesc)) # check category exclusions def closure(module): todo = result = module while todo: result |= todo todo = todo.mapped('dependencies_id.depend_id') return result for category in install_mods.mapped('category_id').filtered('exclusive'): # the installation is valid if all installed modules in category # correspond to one module and all its dependencies in category category_mods = install_mods.filtered(lambda mod: mod.category_id == category) if not any(closure(module) & category_mods == category_mods for module in category_mods): msg = _('You are trying to install incompatible modules in category "%s":') labels = dict(self.fields_get(['state'])['state']['selection']) raise UserError("\n".join([msg % category.name] + [ "- %s (%s)" % (module.shortdesc, labels[module.state]) for module in category_mods ])) return dict(ACTION_DICT, name=_('Install'))
def button_install(self): # domain to select auto-installable (but not yet installed) modules auto_domain = [('state', '=', 'uninstalled'), ('auto_install', '=', True)] # determine whether an auto-install module must be installed: # - all its dependencies are installed or to be installed, # - at least one dependency is 'to install' install_states = frozenset(('installed', 'to install', 'to upgrade')) def must_install(module): states = set(dep.state for dep in module.dependencies_id) return states <= install_states and 'to install' in states modules = self while modules: # Mark the given modules and their dependencies to be installed. modules.state_update('to install', ['uninstalled']) # Determine which auto-installable modules must be installed. modules = self.search(auto_domain).filtered(must_install) # retrieve the installed (or to be installed) theme modules theme_category = self.env.ref('base.module_category_theme') theme_modules = self.search([ ('state', 'in', list(install_states)), ('category_id', 'child_of', [theme_category.id]), ]) # determine all theme modules that mods depends on, including mods def theme_deps(mods): deps = mods.mapped('dependencies_id.depend_id') while deps: mods |= deps deps = deps.mapped('dependencies_id.depend_id') return mods & theme_modules if any(module.state == 'to install' for module in theme_modules): # check: the installation is valid if all installed theme modules # correspond to one theme module and all its theme dependencies if not any(theme_deps(module) == theme_modules for module in theme_modules): state_labels = dict(self.fields_get(['state'])['state']['selection']) themes_list = [ "- %s (%s)" % (module.shortdesc, state_labels[module.state]) for module in theme_modules ] raise UserError(_( "You are trying to install incompatible themes:\n%s\n\n" \ "Please uninstall your current theme before installing another one.\n" "Warning: switching themes may significantly alter the look of your current website pages!" ) % ("\n".join(themes_list))) return dict(ACTION_DICT, name=_('Install'))