def install_report(self, cr, uid, ids, context=None): report_obj = self.pool.get("ir.actions.report.xml") this = self.browse(cr, uid, ids[0], context=context) if report_obj.search(cr, uid, [("report_name", "=", this.name)], context=context): raise osv.except_osv(_("Warning!"), _('Report with service name "%s" already exist in system!') % this.name) fd = StringIO() fd.write(base64.decodestring(this.file)) fd.seek(0) convert_xml_import(cr, "report_aeroo", fd, {}, "init", noupdate=True) fd.close() self.write(cr, uid, ids, {"state": "done"}, context=context) report_id = report_obj.search(cr, uid, [("report_name", "=", this.name)], context=context)[-1] report = report_obj.browse(cr, uid, report_id, context=context) event_id = self.pool.get("ir.values").set_action( cr, uid, report.report_name, "client_print_multi", report.model, "ir.actions.report.xml,%d" % report_id ) if report.report_wizard: report._set_report_wizard(report.id) mod_obj = self.pool.get("ir.model.data") act_obj = self.pool.get("ir.actions.act_window") mod_id = mod_obj.search(cr, uid, [("name", "=", "action_aeroo_report_xml_tree")])[0] res_id = mod_obj.read(cr, uid, mod_id, ["res_id"])["res_id"] act_win = act_obj.read(cr, uid, res_id, []) act_win["domain"] = [("id", "=", report_id)] return act_win
def import_local(self): res = super(L10nEsPartnerImportWizard, self).execute() path = os.path.join('l10n_es_partner', 'wizard', 'data_banks.xml') with tools.file_open(path) as fp: tools.convert_xml_import( self._cr, 'l10n_es_partner', fp, {}, 'init', noupdate=False) return res
def _load_data(cr, module_name, idref, mode, kind): """ kind: data, demo, test, init_xml, update_xml, demo_xml. noupdate is False, unless it is demo data or it is csv data in init mode. """ for filename in package.data[kind]: log = logging.getLogger('init') log.info("module %s: loading %s", module_name, filename) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) fp = tools.file_open(pathname) noupdate = False if kind in ('demo', 'demo_xml'): noupdate = True try: if ext == '.csv': if kind in ('init', 'init_xml'): noupdate = True tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate) elif ext == '.sql': process_sql_file(cr, fp) elif ext == '.yml': tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate) else: tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report) finally: fp.close()
def import_local(self): res = super(L10nEsPartnerImportWizard, self).execute() path = os.path.join('l10n_es_partner', 'wizard', 'data_banks.xml') with tools.file_open(path) as fp: tools.convert_xml_import( self._cr, 'l10n_es_partner', fp, {}, 'init', noupdate=True) return res
def execute(self): import requests src_file = tempfile.NamedTemporaryFile(delete=False) dest_file = tempfile.NamedTemporaryFile('w', delete=False) try: response = requests.get( 'http://www.bde.es/f/webbde/IFI/servicio/regis/ficheros/es/' 'REGBANESP_CONESTAB_A.XLS') if not response.ok: raise Exception() src_file.write(response.content) src_file.close() # Generate XML and reopen it gen_bank_data_xml(src_file.name, dest_file.name) tools.convert_xml_import( self._cr, 'l10n_es_partner', dest_file.name, {}, 'init', noupdate=True) except: self.import_fail = True return { 'name': _('Import spanish bank data'), 'type': 'ir.actions.act_window', 'res_model': 'l10n.es.partner.import.wizard', 'view_id': self.env.ref("l10n_es_partner." "l10n_es_partner_import_wizard").id, 'view_type': 'form', 'view_mode': 'form', 'res_id': self.id, 'target': 'new', } finally: os.remove(src_file.name) os.remove(dest_file.name)
def _load_data(cr, module_name, idref, mode, kind): """ kind: data, demo, test, init_xml, update_xml, demo_xml. noupdate is False, unless it is demo data or it is csv data in init mode. """ for filename in package.data[kind]: _logger.info("module %s: loading %s", module_name, filename) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) fp = tools.file_open(pathname) noupdate = False if kind in ('demo', 'demo_xml'): noupdate = True try: ext = ext.lower() if ext == '.csv': if kind in ('init', 'init_xml'): noupdate = True tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate) elif ext == '.sql': process_sql_file(cr, fp) elif ext == '.yml': tools.convert_yaml_import(cr, module_name, fp, kind, idref, mode, noupdate, report) elif ext == '.xml': tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report) elif ext == '.js': pass # .js files are valid but ignored here. else: _logger.warning("Can't load unknown file type %s.", filename) finally: fp.close()
def install_report(self, cr, uid, ids, context=None): report_obj = self.pool.get('ir.actions.report') this = self.browse(cr, uid, ids[0], context=context) if report_obj.search(cr, uid, [('report_name', '=', this.name)], context=context): raise osv.except_osv( _('Warning!'), _('Report with service name "%s" already exist in system!') % this.name) fd = StringIO() fd.write(base64.decodestring(this.file)) fd.seek(0) convert_xml_import(cr, 'report_aeroo', fd, {}, 'init', noupdate=True) fd.close() self.write(cr, uid, ids, {'state': 'done'}, context=context) report_id = report_obj.search(cr, uid, [('report_name', '=', this.name)], context=context)[-1] report = report_obj.browse(cr, uid, report_id, context=context) event_id = self.pool.get('ir.values').set_action( cr, uid, report.report_name, 'client_print_multi', report.model, 'ir.actions.report,%d' % report_id) if report.report_wizard: report._set_report_wizard(report.id) mod_obj = self.pool.get('ir.model.data') act_obj = self.pool.get('ir.actions.act_window') mod_id = mod_obj.search( cr, uid, [('name', '=', 'action_aeroo_report_xml_tree')])[0] res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id'] act_win = act_obj.read(cr, uid, res_id, []) act_win['domain'] = [('id', '=', report_id)] return act_win
def send_form(self, ): account = self[0] #_logger.warning('data %s b64 %s ' % (account.data,base64.decodestring(account.data))) if not account.data == None: fileobj = TemporaryFile('w+') fileobj.write(base64.decodestring(account.data)) fileobj.seek(0) try: tools.convert_xml_import(account._cr, 'account_export', fileobj, None, 'init', False, None) finally: fileobj.close() return True account.write({ 'state': 'get', 'name': '%s.xml' % account.model.model.replace('.', '_'), 'data': base64.b64encode(account._export_xml()) }) return { 'type': 'ir.actions.act_window', 'res_model': 'account.export', 'view_mode': 'form', 'view_type': 'form', 'res_id': account.id, 'views': [(False, 'form')], 'target': 'new', }
def install_report(self, cr, uid, ids, context=None): report_obj = self.pool.get('ir.actions.report.xml') this = self.browse(cr, uid, ids[0], context=context) if report_obj.search(cr, uid, [('report_name','=',this.name)], context=context): raise orm.except_orm(_('Warning!'), _('Report with service name "%s" already exist in system!') % this.name) fd = StringIO() fd.write(base64.decodestring(this.file)) fd.seek(0) convert_xml_import(cr, 'report_aeroo', fd, {}, 'init', noupdate=True) fd.close() self.write(cr, uid, ids, {'state':'done'}, context=context) report_id = report_obj.search(cr, uid, [('report_name','=',this.name)], context=context)[-1] report = report_obj.browse(cr, uid, report_id, context=context) event_id = self.pool.get('ir.values').set_action(cr, uid, report.report_name, 'client_print_multi', report.model, 'ir.actions.report.xml,%d' % report_id) if report.report_wizard: report._set_report_wizard(report.id) mod_obj = self.pool.get('ir.model.data') act_obj = self.pool.get('ir.actions.act_window') mod_id = mod_obj.search(cr, uid, [('name', '=', 'action_aeroo_report_xml_tree')])[0] res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id'] act_win = act_obj.read(cr, uid, res_id, []) act_win['domain'] = [('id','=',report_id)] return act_win
def execute(self): import urllib2 try: xlsfile = urllib2.urlopen( 'http://www.bde.es/f/webbde/IFI/servicio/regis/ficheros/es/' 'REGBANESP_CONESTAB_A.XLS') # Read XLS src_file = tempfile.NamedTemporaryFile(delete=False) src_file.write(xlsfile.read()) src_file.close() # Prepare XML dest file dest_file = tempfile.NamedTemporaryFile('w', delete=False) dest_file.close() # Generate XML and reopen it gen_bank_data_xml(src_file.name, dest_file.name) tools.convert_xml_import( self._cr, 'l10n_es_partner', dest_file.name, {}, 'init', noupdate=False) except: self.import_fail = True return { 'name': _('Import spanish bank data'), 'type': 'ir.actions.act_window', 'res_model': 'l10n.es.partner.import.wizard', 'view_id': self.env.ref("l10n_es_partner." "l10n_es_partner_import_wizard").id, 'view_type': 'form', 'view_mode': 'form', 'res_id': self.id, 'target': 'new', } finally: dest_file.close() os.remove(src_file.name) os.remove(dest_file.name)
def create_zipcodes(self): """Import spanish zipcodes information through an XML file.""" file_name = 'l10n_es_toponyms_zipcodes.xml' path = os.path.join('l10n_es_toponyms', 'wizard', file_name) with tools.file_open(path) as fp: tools.convert_xml_import(self.env.cr, 'l10n_es_toponyms', fp, {}, 'init', noupdate=True) return True
def execute(self, cr, uid, ids, context=None): super(L10nEsPartnerImportWizard, self).execute(cr, uid, ids, context=context) path = os.path.join('l10n_es_partner', 'wizard', 'data_banks.xml') with tools.file_open(path) as fp: tools.convert_xml_import(cr, 'l10n_es_partner', fp, {}, 'init', noupdate=True) return {}
def xml_import_report(self, cr, uid, ids, context=None): """ To get the module and extract the xml report definition @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in @param context: A standard dictionary @return : retrun report """ if context is None: context = {} list_report = [] values = self.read(cr, uid, ids, context=context)[0] module_id = values['module_id'][0] if module_id: module = self.pool.get('ir.module.module').browse(cr,uid, module_id) pathname = CD_ODOO_ADDONS + module.name + "/Report_def/" print 'PathName : ',pathname list_report = listdir(pathname) print 'liste des rapports à importer ', list_report for filename in list_report: open_file = pathname + filename fp = tools.file_open(open_file) obj_xml_odoo = odoo_xml(fp) my_models = obj_xml_odoo.get_xml_all_models() print my_models # Completion of external models new_list_models = list(my_models) for name_model in new_list_models: print 'name model ', name_model my_models = self.external_models(cr,uid,name_model,my_models) print 'export des Id', my_models pool_ir_data = self.pool.get('ir.model.data') for rec_model in my_models: print 'model exporte ',rec_model pool_ir_data.export_external_ids(cr,uid,rec_model,module_id) fp.close() print 'conversion des fichiers XML' for filename in list_report: open_file = pathname + filename print ' open_file ',open_file fp = tools.file_open(open_file) try: print 'XML to report',module.name tools.convert_xml_import(cr, module.name, fp, None, 'init', True, None) finally: fp.close()
def create_zipcodes(self, cr, uid, context=None): """Import spanish zipcodes information through an XML file.""" file_name = 'l10n_es_toponyms_zipcodes.xml' path = os.path.join('l10n_es_toponyms', 'wizard', file_name) with tools.file_open(path) as fp: tools.convert_xml_import(cr, 'l10n_es_toponyms', fp, {}, 'init', noupdate=True) return True return False
def load_data(cr, module_name, fp, idref=None, mode='init', noupdate=False, report=None): pathname = os.path.join(module_name, fp) fp = get_file(module_name, fp) _logger.info("Import datas from %s" % pathname) convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
def create_states(self, state_type): """Import spanish states information through an XML file.""" file_name = 'l10n_es_toponyms_states_%s.xml' % state_type path = os.path.join('l10n_es_toponyms', 'wizard', file_name) with tools.file_open(path) as fp: tools.convert_xml_import(self.env.cr, 'l10n_es_toponyms', fp, {}, 'init', noupdate=True) return True
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 load_data(cr, module_name, fp, idref=None, mode='init', noupdate=False, report=None): pathname = os.path.join(module_name, fp) fp = get_file(module_name, fp) _logger.info("Import datas from %s" % pathname) try: convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report) except: _logger.info("%s already exists in database" % fp) pass
def _import_file(self, cr, mode, f_obj, module): root, ext = os.path.splitext(f_obj.name) if ext == '.sql': self._sql_import(cr, f_obj) elif mode != 'pre-load' and ext == '.yml': with api.Environment.manage(): tools.convert_yaml_import(cr, module, f_obj, 'upgrade') elif mode != 'pre-load' and ext == '.csv': tools.convert_csv_import(cr, module, f_obj.name, f_obj.read(), 'upgrade') elif mode != 'pre-load' and ext == '.xml': tools.convert_xml_import(cr, module, f_obj, 'upgrade') else: _logger.error('%s extension is not supported in upgrade %sing', ext, mode) pass
class config_es_toponyms(osv.osv_memory): _name='config.es.toponyms' _inherit = 'res.config.installer' _columns = { 'name':fields.char('Name', size=64), 'state': fields.selection([('official','Official'),('spanish','Spanish'),('both','Both')], 'State names', required=True), 'city_info': fields.selection([('yes','Yes'),('no','No')], 'City information', required=True), } _defaults={ 'state': lambda *args: 'official', 'city_info': lambda *args: 'yes', } def create_states(self, cr, uid, state_type, context=None): """Import spanish states information through an XML file.""" file_name = 'l10n_es_toponyms_states_%s.xml' %state_type try: fp = tools.file_open(os.path.join('l10n_es_toponyms', os.path.join('wizard', file_name))) except IOError, e: fp = None if fp: idref = {} tools.convert_xml_import(cr, 'l10n_es_toponyms', fp, idref, 'init', noupdate=True) cr.commit() return True return False
def _load_data(cr, module_name, idref, mode, kind): """ kind: data, demo, test, init_xml, update_xml, demo_xml. noupdate is False, unless it is demo data or it is csv data in init mode. """ skip_list = [] ignore_xml_on_installed = package.data.get('ignore_xml_on_installed') if ignore_xml_on_installed: check_modules = ignore_xml_on_installed.keys() if check_modules: cr.execute(''' SELECT name FROM ir_module_module WHERE name = ANY(ARRAY%s) AND state in ('installed','to_upgrade')''' % check_modules) for installed_module, in cr.fetchall(): skip_list.extend(ignore_xml_on_installed[installed_module]) for filename in package.data[kind]: _logger.info("module %s: loading %s", module_name, filename) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) if filename in skip_list: continue fp = tools.file_open(pathname) noupdate = False if kind in ('demo', 'demo_xml'): noupdate = True try: if ext == '.csv': if kind in ('init', 'init_xml'): noupdate = True tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate) elif ext == '.sql': process_sql_file(cr, fp) elif ext == '.yml': tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate) else: tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report) finally: fp.close()
def load_data(cr, module_name, filename, idref=None, mode='init'): """ Load an xml, csv or yml data file from your post script. The usual case for this is the occurrence of newly added essential or useful data in the module that is marked with "noupdate='1'" and without "forcecreate='1'" so that it will not be loaded by the usual upgrade mechanism. Leaving the 'mode' argument to its default 'init' will load the data from your migration script. Theoretically, you could simply load a stock file from the module, but be careful not to reinitialize any data that could have been customized. Preferably, select only the newly added items. Copy these to a file in your migrations directory and load that file. Leave it to the user to actually delete existing resources that are marked with 'noupdate' (other named items will be deleted automatically). :param module_name: the name of the module :param filename: the path to the filename, relative to the module \ directory. :param idref: optional hash with ?id mapping cache? :param mode: one of 'init', 'update', 'demo'. Always use 'init' \ for adding new items from files that are marked with 'noupdate'. Defaults \ to 'init'. """ if idref is None: idref = {} logger.info('%s: loading %s' % (module_name, filename)) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) fp = tools.file_open(pathname) try: if ext == '.csv': noupdate = True tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate) elif ext == '.yml': yaml_import(cr, module_name, fp, None, idref=idref, mode=mode) else: tools.convert_xml_import(cr, module_name, fp, idref, mode=mode) finally: fp.close()
def load_data(cr, module_name, filename, idref=None, mode='init'): """ Load an xml, csv or yml data file from your post script. The usual case for this is the occurrence of newly added essential or useful data in the module that is marked with "noupdate='1'" and without "forcecreate='1'" so that it will not be loaded by the usual upgrade mechanism. Leaving the 'mode' argument to its default 'init' will load the data from your migration script. Theoretically, you could simply load a stock file from the module, but be careful not to reinitialize any data that could have been customized. Preferably, select only the newly added items. Copy these to a file in your migrations directory and load that file. Leave it to the user to actually delete existing resources that are marked with 'noupdate' (other named items will be deleted automatically). :param module_name: the name of the module :param filename: the path to the filename, relative to the module \ directory. :param idref: optional hash with ?id mapping cache? :param mode: one of 'init', 'update', 'demo'. Always use 'init' \ for adding new items from files that are marked with 'noupdate'. Defaults \ to 'init'. """ if idref is None: idref = {} logger.info('%s: loading %s' % (module_name, filename)) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) fp = tools.file_open(pathname) try: if ext == '.csv': noupdate = True tools.convert_csv_import( cr, module_name, pathname, fp.read(), idref, mode, noupdate) elif ext == '.yml': yaml_import(cr, module_name, fp, None, idref=idref, mode=mode) else: tools.convert_xml_import(cr, module_name, fp, idref, mode=mode) finally: fp.close()
def execute(self, cr, uid, ids, context=None): super(L10nEsPartnerImportWizard, self).execute(cr, uid, ids, context=context) try: fp = tools.file_open( os.path.join('l10n_es_partner', 'wizard', 'data_banks.xml')) except IOError: return {} idref = {} tools.convert_xml_import(cr, 'l10n_es_partner', fp, idref, 'init', noupdate=True) fp.close() return {}
def send_form(self,): account = self[0] #_logger.warning('data %s b64 %s ' % (account.data,base64.decodestring(account.data))) if not account.data == None: fileobj = TemporaryFile('w+') fileobj.write(base64.decodestring(account.data)) fileobj.seek(0) try: tools.convert_xml_import(account._cr, 'account_export', fileobj, None, 'init', False, None) finally: fileobj.close() return True account.write({'state': 'get', 'name': '%s.xml' % account.model.model.replace('.','_'),'data': base64.b64encode(account._export_xml()) }) return { 'type': 'ir.actions.act_window', 'res_model': 'account.export', 'view_mode': 'form', 'view_type': 'form', 'res_id': account.id, 'views': [(False, 'form')], 'target': 'new', }
def _run_test(cr, module, filename): _, ext = os.path.splitext(filename) pathname = os.path.join(module, filename) with tools.file_open(pathname) as fp: if ext == '.sql': if hasattr(tools, 'convert_sql_import'): tools.convert_sql_import(cr, fp) else: queries = fp.read().split(';') for query in queries: new_query = ' '.join(query.split()) if new_query: cr.execute(new_query) elif ext == '.csv': tools.convert_csv_import(cr, module, pathname, fp.read(), idref=None, mode='update', noupdate=False) elif ext == '.yml': if LooseVersion(release.major_version) >= LooseVersion('7.0'): tools.convert_yaml_import(cr, module, fp, kind='test', idref=None, mode='update', noupdate=False) else: tools.convert_yaml_import(cr, module, fp, idref=None, mode='update', noupdate=False) elif ext == '.xml': tools.convert_xml_import(cr, module, fp, idref=None, mode='update', noupdate=False)
def _load_data(self, module_name, kind='demo', mode='update', noupdate=False): cr = self._cr info = load_information_from_description_file(module_name) for filename in info.get(kind, []): _logger.info('loading %s/%s...' % (module_name, filename)) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) with tools.file_open(pathname) as fp: if ext == '.sql': tools.convert_sql_import(cr, fp) elif ext == '.csv': tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref=None, mode=mode, noupdate=noupdate) elif ext == '.yml': tools.convert_yaml_import(cr, module_name, fp, kind=kind, idref=None, mode=mode, noupdate=noupdate) elif ext == '.xml': tools.convert_xml_import(cr, module_name, fp, idref=None, mode=mode, noupdate=noupdate) return True
class l10n_es_partner_import_wizard(orm.TransientModel): _name = 'l10n.es.partner.import.wizard' _inherit = 'res.config.installer' def execute(self, cr, uid, ids, context=None): if context is None: context = {} super(l10n_es_partner_import_wizard, self).execute(cr, uid, ids, context=context) try: fp = tools.file_open(os.path.join(os.path.join('l10n_es_partner', 'wizard'), 'data_banks.xml')) except IOError, e: return {} idref = {} tools.convert_xml_import(cr, 'l10n_es_partner', fp, idref, 'init', noupdate=True) fp.close() return {}
def setUp(self): super(TestReversal, self).setUp() # load xml data convert_xml_import(self.cr, MODULE, DATA, {}, 'update')
def load_data(self, cr, uid, load=[]): """ Load data defined on test case `data` attribute """ module = self.get_current_instance_module() for file in load: if not isinstance(file, dict): data = {'module': module, 'file': file} else: data = file if not [name for name in ['module', 'file'] if name in data]: raise Exception('Test case data entry is not valid: %s', data) if data.get('uid', False): data.update({'uid': self.full_ref(data['uid'])}) else: data.update({'uid': SUPERUSER_ID}) self.log.debug("module %s: loading %s (User ID: %s)", data['module'], data['file'], data['uid']) _, ext = os.path.splitext(data['file']) pathname = os.path.join(data['module'], data['file']) fp = tools.file_open(pathname) noupdate = False # fake these incomprehensible params... idref = {} mode = 'update' kind = 'data' report = None # copy from server/openerp/modules/loading.py:66... def process_sql_file(cr, fp): queries = fp.read().split(';') for query in queries: new_query = ' '.join(query.split()) if new_query: cr.execute(new_query) try: ext = ext.lower() if ext == '.csv': # TODO: Migrate the feature below to v8 # allow to specify a user when importing data. By default, # use the superuser. tools.convert_csv_import(cr, module, pathname, fp.read(), idref, mode, noupdate) elif ext == '.sql': process_sql_file(cr, fp) elif ext == '.yml': tools.convert_yaml_import(cr, module, fp, kind, idref, mode, noupdate, report) elif ext == '.xml': tools.convert_xml_import(cr, module, fp, idref, mode, noupdate, report) else: self.log.warning("Can't load unknown file type %s.", data['file']) finally: fp.close()
def _run_xml(self): convert_xml_import(self._cr, __package__, StringIO(self.code.encode('utf-8'))) return 'No expected result'
def _run_xml(self, cr, uid, script, context=None): convert_xml_import(cr, __package__, StringIO(script.code.encode('utf-8'))) return 'No expected result'
def setUp(self): super(TestHrStreamline, self).setUp() # load xml data convert_xml_import(self.cr, 'hr_streamline', DATA, {}, 'update')
idref = {} tools.convert_xml_import(cr, 'l10n_es_toponyms', fp, idref, 'init', noupdate=True) cr.commit() return True return False def create_zipcodes(self, cr, uid, context=None): """Import spanish zipcodes information through an XML file.""" file_name = 'l10n_es_toponyms_zipcodes.xml' try: fp = tools.file_open(os.path.join('l10n_es_toponyms', os.path.join('wizard', file_name))) except IOError, e: fp = None if fp: idref = {} tools.convert_xml_import(cr, 'l10n_es_toponyms', fp, idref, 'init', noupdate=True) cr.commit() return True return False def execute(self, cr, uid, ids, context=None): if context is None: context = {} super(config_es_toponyms, self).execute(cr, uid, ids, context=context) res = self.read(cr, uid, ids)[0] # Import spanish states (official, Spanish or both) self.create_states(cr, uid, res['state'], context=context) # Import spanish cities and zip codes if res['city_info'] == 'yes': self.create_zipcodes(cr, uid, context=context) config_es_toponyms()