def install_report(self): report_obj = self.env['ir.actions.report.xml'] this = self.browse(self.ids[0]) if report_obj.search([('report_name', '=', this.name)]): raise UserError( _('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(self.env.cr, 'report_aeroo', fd, {}, 'init', noupdate=True) fd.close() self.write({'state': 'done'}) report_id = report_obj.search([('report_name', '=', this.name)])[-1] report = report_obj.browse(report_id) event_id = self.env['ir.values'].set_action( self.env.cr, self.env.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.env['ir.model.data'] act_obj = self.env['ir.actions.act_window'] mod_id = mod_obj.search([('name', '=', 'action_aeroo_report_xml_tree') ])[0] res_id = mod_obj.read(mod_id, ['res_id'])['res_id'] act_win = act_obj.read(res_id, []) act_win['domain'] = [('id', '=', report_id)] return act_win
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 _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 in ('.yml', '.csv', '.xml'): with api.Environment.manage(): if ext == '.yml': tools.convert_yaml_import(cr, module, yamlfile=f_obj, kind=None, mode='upgrade') elif ext == '.csv': tools.convert_csv_import(cr, module, fname=f_obj.name, csvcontent=f_obj.read(), mode='upgrade') elif ext == '.xml': tools.convert_xml_import(cr, module, xmlfile=f_obj, mode='upgrade') else: _logger.error('%s extension is not supported in upgrade %sing', ext, mode)
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') response.raise_for_status() 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 requests.exceptions.HTTPError: # pragma: no cover _logger.exception() 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 multi_add(self, filename): file = path.join(path.dirname(path.dirname(path.abspath(__file__)))) + filename if (constants.LYRA_PLUGIN_FEATURES.get('multi') == True): convert_xml_import(self._cr, 'payment_lyra', file) return None
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 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 _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, 'rb') 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 == '.xml': tools.convert_xml_import(cr, module_name, fp, idref=None, mode=mode, noupdate=noupdate) return True
def _import_demo_data(cls): module = 'smile_account_asset' for filename in ('account_demo.xml', 'account_tax_demo.xml', 'account_asset_category_demo.xml', 'account_asset_demo.xml', 'res_company_demo.xml'): filepath = os.path.join(module, 'demo', filename) with tools.file_open(filepath) as xmlfile: tools.convert_xml_import(cls.env.cr, module, xmlfile=xmlfile)
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 import_local(self): res = super().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 _run_xml(self): self.ensure_one() # Patch StringIO object with missing name attribute # The name attribute is required by the odoo function convert_xml_import stringio = StringIO(self.code) stringio.name = self.name convert_xml_import(self._cr, __package__, stringio) return 'No expected result'
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") response.raise_for_status() 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 requests.exceptions.HTTPError: # pragma: no cover _logger.exception("HTTP Error while importing data") 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_mode": "form", "res_id": self.id, "target": "new", } finally: os.remove(src_file.name) os.remove(dest_file.name)
def _run_xml(self): self.ensure_one() convert_xml_import(self._cr, __package__, StringIO(self.code)) return 'No expected result'