def __init__(self, db_name): self.models = {} # model name/model instance mapping self._sql_error = {} self._store_function = {} self._init = True self._init_parent = {} self._assertion_report = assertion_report.assertion_report() # modules fully loaded (maintained during init phase by `loading` module) self._init_modules = set() self.db_name = db_name self.db = openerp.sql_db.db_connect(db_name) # In monoprocess cron jobs flag (pooljobs) self.cron = False # Inter-process signaling (used only when openerp.multi_process is True): # The `base_registry_signaling` sequence indicates the whole registry # must be reloaded. # The `base_cache_signaling sequence` indicates all caches must be # invalidated (i.e. cleared). self.base_registry_signaling_sequence = 1 self.base_cache_signaling_sequence = 1 # Flag indicating if at least one model cache has been cleared. # Useful only in a multi-process context. self._any_cache_cleared = False cr = self.db.cursor() has_unaccent = openerp.modules.db.has_unaccent(cr) if openerp.tools.config['unaccent'] and not has_unaccent: _logger.warning("The option --unaccent was given but no unaccent() function was found in database.") self.has_unaccent = openerp.tools.config['unaccent'] and has_unaccent cr.close()
def test_purchase(self, cr, uid, ids, context=None): if context == None: context = {} assertion_obj = assertion_report.assertion_report() this = self.browse(cr, uid, ids)[0] fp_data = tools.file_open(os.path.join( 'purchase_test_data_imp', 'test/purchase_order_test_data.xml')) fp_test = tools.file_open(os.path.join( 'purchase_test_data_imp', 'test/purchase_order_product_can_be_purchased.yml')) try: cr.execute("SAVEPOINT test_yaml_purchase_savepoint") context.update({'uid': uid}) tools.convert_xml_import(cr, 'purchase_test_data_imp', fp_data, { }, 'init', False, assertion_obj) tools.convert_yaml_import(cr, 'purchase_test_data_imp', fp_test, 'test', { }, 'init', False, assertion_obj, context=context) finally: if this.test_commit: cr.execute("RELEASE SAVEPOINT test_yaml_purchase_savepoint") else: cr.execute("ROLLBACK TO test_yaml_purchase_savepoint") fp_data.close() fp_test.close() tmp_path = tempfile.gettempdir() file_purchase_order_wrong = base64.encodestring( open(os.path.join(tmp_path, 'purchase_order_product_log.csv'), 'rb+').read()) file_purchase_order_log = base64.encodestring( open(os.path.join(tmp_path, 'purchase_order_general_log.csv'), 'rb+').read()) self.write(cr, uid, ids, { 'yaml_file': file_purchase_order_wrong, 'yaml_file_log': file_purchase_order_log, 'filename_product': 'purchase_order_product_log.csv', 'filename_log_general': 'purchase_order_general_log.csv', }, context=context) __, xml_id = self.pool.get('ir.model.data').get_object_reference( cr, uid, 'purchase_test_data_imp', 'view_wizard_purchase_test_data_result') return { 'res_model': 'test.yaml.data.purchase', 'view_type': 'form', 'view_mode': 'form', 'view_id': xml_id, 'res_id': this.id, 'context': context, 'type': 'ir.actions.act_window', 'target': 'new', }
def __init__(self, db_name): super(Registry, self).__init__() self.models = {} # model name/model instance mapping self._sql_error = {} self._store_function = {} self._pure_function_fields = {} # {model: [field, ...], ...} self._init = True self._init_parent = {} self._assertion_report = assertion_report.assertion_report() self._fields_by_model = None # modules fully loaded (maintained during init phase by `loading` module) self._init_modules = set() self.db_name = db_name self._db = openerp.sql_db.db_connect(db_name) # special cursor for test mode; None means "normal" mode self.test_cr = None # Indicates that the registry is self.ready = False # Inter-process signaling (used only when openerp.multi_process is True): # The `base_registry_signaling` sequence indicates the whole registry # must be reloaded. # The `base_cache_signaling sequence` indicates all caches must be # invalidated (i.e. cleared). self.base_registry_signaling_sequence = None self.base_cache_signaling_sequence = None self.cache = LRU(8192) # Flag indicating if at least one model cache has been cleared. # Useful only in a multi-process context. self._any_cache_cleared = False cr = self.cursor() has_unaccent = openerp.modules.db.has_unaccent(cr) if openerp.tools.config['unaccent'] and not has_unaccent: _logger.warning( "The option --unaccent was given but no unaccent() function was found in database." ) self.has_unaccent = openerp.tools.config['unaccent'] and has_unaccent #OpenUpgrade: ir_model must be in 9.0 format before continuing openupgrade_loading_90.migrate_model_tables(cr) cr.close()
def __init__(self, db_name): super(Registry, self).__init__() self.models = {} # model name/model instance mapping self._sql_error = {} self._store_function = {} self._pure_function_fields = {} # {model: [field, ...], ...} self._init = True self._init_parent = {} self._assertion_report = assertion_report.assertion_report() self._fields_by_model = None # modules fully loaded (maintained during init phase by `loading` module) self._init_modules = set() self.db_name = db_name self._db = openerp.sql_db.db_connect(db_name) # special cursor for test mode; None means "normal" mode self.test_cr = None # Indicates that the registry is self.ready = False # Inter-process signaling (used only when openerp.multi_process is True): # The `base_registry_signaling` sequence indicates the whole registry # must be reloaded. # The `base_cache_signaling sequence` indicates all caches must be # invalidated (i.e. cleared). self.base_registry_signaling_sequence = None self.base_cache_signaling_sequence = None self.cache = LRU(8192) # Flag indicating if at least one model cache has been cleared. # Useful only in a multi-process context. self._any_cache_cleared = False cr = self.cursor() has_unaccent = openerp.modules.db.has_unaccent(cr) if openerp.tools.config['unaccent'] and not has_unaccent: _logger.warning("The option --unaccent was given but no unaccent() function was found in database.") self.has_unaccent = openerp.tools.config['unaccent'] and has_unaccent cr.close()
def __init__(self, db_name): super(Registry, self).__init__() self.models = {} # model name/model instance mapping self._sql_error = {} self._store_function = {} self._init = True self._init_parent = {} self._assertion_report = assertion_report.assertion_report() self.fields_by_model = None # modules fully loaded (maintained during init phase by `loading` module) self._init_modules = set() self.db_name = db_name self.db = openerp.sql_db.db_connect(db_name) # Indicates that the registry is self.ready = False # Inter-process signaling (used only when openerp.multi_process is True): # The `base_registry_signaling` sequence indicates the whole registry # must be reloaded. # The `base_cache_signaling sequence` indicates all caches must be # invalidated (i.e. cleared). self.base_registry_signaling_sequence = 1 self.base_cache_signaling_sequence = 1 # Flag indicating if at least one model cache has been cleared. # Useful only in a multi-process context. self._any_cache_cleared = False cr = self.db.cursor() has_unaccent = openerp.modules.db.has_unaccent(cr) if openerp.tools.config['unaccent'] and not has_unaccent: _logger.warning( "The option --unaccent was given but no unaccent() function was found in database." ) self.has_unaccent = openerp.tools.config['unaccent'] and has_unaccent cr.close()
def load_modules(db, force_demo=False, status=None, update_module=False): # TODO status['progress'] reporting is broken: used twice (and reset each # time to zero) in load_module_graph, not fine-grained enough. # It should be a method exposed by the pool. initialize_sys_path() open_openerp_namespace() force = [] if force_demo: force.append('demo') cr = db.cursor() try: if not openerp.modules.db.is_initialized(cr): _logger.info("init db") openerp.modules.db.initialize(cr) tools.config["init"]["all"] = 1 tools.config['update']['all'] = 1 if not tools.config['without_demo']: tools.config["demo"]['all'] = 1 # This is a brand new pool, just created in pooler.get_db_and_pool() pool = pooler.get_pool(cr.dbname) if 'base' in tools.config['update'] or 'all' in tools.config['update']: cr.execute("update ir_module_module set state=%s where name=%s and state=%s", ('to upgrade', 'base', 'installed')) # STEP 1: LOAD BASE (must be done before module dependencies can be computed for later steps) graph = openerp.modules.graph.Graph() graph.add_module(cr, 'base', force) if not graph: _logger.critical('module base cannot be loaded! (hint: verify addons-path)') raise osv.osv.except_osv(_('Could not load base module'), _('module base cannot be loaded! (hint: verify addons-path)')) # processed_modules: for cleanup step after install # loaded_modules: to avoid double loading report = assertion_report.assertion_report() loaded_modules, processed_modules = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report) if tools.config['load_language']: for lang in tools.config['load_language'].split(','): tools.load_language(cr, lang) # STEP 2: Mark other modules to be loaded/updated if update_module: modobj = pool.get('ir.module.module') if ('base' in tools.config['init']) or ('base' in tools.config['update']): _logger.info('updating modules list') modobj.update_list(cr, 1) _check_module_names(cr, itertools.chain(tools.config['init'].keys(), tools.config['update'].keys())) mods = [k for k in tools.config['init'] if tools.config['init'][k]] if mods: ids = modobj.search(cr, SUPERUSER_ID, ['&', ('state', '=', 'uninstalled'), ('name', 'in', mods)]) if ids: modobj.button_install(cr, SUPERUSER_ID, ids) mods = [k for k in tools.config['update'] if tools.config['update'][k]] if mods: ids = modobj.search(cr, SUPERUSER_ID, ['&', ('state', '=', 'installed'), ('name', 'in', mods)]) if ids: modobj.button_upgrade(cr, SUPERUSER_ID, ids) cr.execute("update ir_module_module set state=%s where name=%s", ('installed', 'base')) # STEP 3: Load marked modules (skipping base which was done in STEP 1) # IMPORTANT: this is done in two parts, first loading all installed or # partially installed modules (i.e. installed/to upgrade), to # offer a consistent system to the second part: installing # newly selected modules. # We include the modules 'to remove' in the first step, because # they are part of the "currently installed" modules. They will # be dropped in STEP 6 later, before restarting the loading # process. states_to_load = ['installed', 'to upgrade', 'to remove'] processed = load_marked_modules(cr, graph, states_to_load, force, status, report, loaded_modules) processed_modules.extend(processed) if update_module: states_to_load = ['to install'] processed = load_marked_modules(cr, graph, states_to_load, force, status, report, loaded_modules) processed_modules.extend(processed) # load custom models cr.execute('select model from ir_model where state=%s', ('manual',)) for model in cr.dictfetchall(): pool.get('ir.model').instanciate(cr, SUPERUSER_ID, model['model'], {}) # STEP 4: Finish and cleanup installations if processed_modules: cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""") for (model, name) in cr.fetchall(): model_obj = pool.get(model) if model_obj and not model_obj.is_transient(): _logger.warning('Model %s (%s) has no access rules!', model, name) # Temporary warning while we remove access rights on osv_memory objects, as they have # been replaced by owner-only access rights cr.execute("""select distinct mod.model, mod.name from ir_model_access acc, ir_model mod where acc.model_id = mod.id""") for (model, name) in cr.fetchall(): model_obj = pool.get(model) if model_obj and model_obj.is_transient(): _logger.warning('The transient model %s (%s) should not have explicit access rules!', model, name) cr.execute("SELECT model from ir_model") for (model,) in cr.fetchall(): obj = pool.get(model) if obj: obj._check_removed_columns(cr, log=True) else: _logger.warning("Model %s is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)", model) # Cleanup orphan records pool.get('ir.model.data')._process_end(cr, SUPERUSER_ID, processed_modules) for kind in ('init', 'demo', 'update'): tools.config[kind] = {} cr.commit() # STEP 5: Cleanup menus # Remove menu items that are not referenced by any of other # (child) menu item, ir_values, or ir_model_data. # TODO: This code could be a method of ir_ui_menu. Remove menu without actions of children if update_module: while True: cr.execute('''delete from ir_ui_menu where (id not IN (select parent_id from ir_ui_menu where parent_id is not null)) and (id not IN (select res_id from ir_values where model='ir.ui.menu')) and (id not IN (select res_id from ir_model_data where model='ir.ui.menu'))''') cr.commit() if not cr.rowcount: break else: _logger.info('removed %d unused menus', cr.rowcount) # STEP 6: Uninstall modules to remove if update_module: # Remove records referenced from ir_model_data for modules to be # removed (and removed the references from ir_model_data). cr.execute("SELECT id FROM ir_module_module WHERE state=%s", ('to remove',)) mod_ids_to_remove = [x[0] for x in cr.fetchall()] if mod_ids_to_remove: pool.get('ir.module.module').module_uninstall(cr, SUPERUSER_ID, mod_ids_to_remove) # Recursive reload, should only happen once, because there should be no # modules to remove next time cr.commit() _logger.info('Reloading registry once more after uninstalling modules') return pooler.restart_pool(cr.dbname, force_demo, status, update_module) if report.failures: _logger.error('At least one test failed when loading the modules.') else: _logger.info('Modules loaded.') finally: cr.close()