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 _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 post_init_hook(cr, registry): path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") file_city = "res.city.csv" with tools.file_open(path + "/" + file_city, mode="rb") as fp: tools.convert_csv_import( cr, "base", file_city, fp.read(), {}, mode="init", noupdate=True, )
def post_init_hook(cr, registry): path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") files = [ "res.country.zone.csv", "res.country.state.csv", "res.country.commune.csv" ] for file in files: with tools.file_open(path + "/" + file, mode="rb") as fp: tools.convert_csv_import( cr, "base", file, fp.read(), {}, mode="init", noupdate=True, ) with api.Environment.manage(): env = api.Environment(cr, SUPERUSER_ID, {}) env["res.partner"]._install_l10n_ro_siruta()
def execute(self): res = super(RomaniaConfigSettings, self).execute() data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') # Load SIRUTA datas if field is checked wiz = self[0] if wiz.siruta_update: # First check if module is installed installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_siruta'), ('state', '=', 'installed') ]) if installed: path = data_dir + '/l10n_ro_siruta/' files = [ 'res.country.zone.csv', 'res.country.state.csv', 'res.country.commune.csv', 'res.country.city.csv' ] for file1 in files: with tools.file_open(path + file1) as fp: tools.convert_csv_import(self._cr, 'l10n_ro_config', file1, fp.read(), {}, mode="init", noupdate=True) account_obj = self.env['account.account'] #------------- # Load Undeductible VAT Configuration installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_invoice_line_not_deductible'), ('state', '=', 'installed') ]) if installed: tax_names = ('TVA deductibil 5%', 'TVA deductibil 9%', 'TVA deductibil 19%', 'TVA deductibil 20%', 'TVA deductibil 24%') taxes = self.env['account.tax'].search([('company_id', '=', self.company_id.id), ('name', 'in', tax_names)]) cols = [col[0] for col in self.env['account.tax']._columns.items()] if 'not_deductible_tax_id' in cols and taxes: for tax in taxes: if not tax.not_deductible_tax_id: not_deduct_tax = self.env['account.tax'].search([ ('company_id', '=', self.company_id.id), ('name', 'ilike', tax.name.replace('deductibil', 'colectat')) ]) if not_deduct_tax: tax.not_deductible_tax_id = not_deduct_tax[0].id # Load Chart of Asset Category installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_asset'), ('state', '=', 'installed') ]) if installed: categ_obj = self.env['account.asset.category'] wiz = self[0] if wiz.asset_category_chart_installed: asset_categ = categ_obj.search([ ('name', '=', 'Catalog Mijloace Fixe'), ('company_id', '=', wiz.company_id.id) ]) if not asset_categ: journal_obj = self.env['account.journal'] journal_id = journal_obj.search([('code', '=', 'AMORT'), ('company_id', '=', wiz.company_id.id)]) # Search for Amortization Journal on company, if doesn't # exist create it. if not journal_id: default_account_id = account_obj.search([ ('code', '=', '681100'), ('company_id', '=', wiz.company_id.id) ]) if default_account_id: journal_id = journal_obj.create({ "name": 'Jurnal amortizare', "code": 'AMORT', "type": 'general', "user_id": self.env.user.id, "default_credit_account_id": default_account_id[0].id, "default_debit_account_id": default_account_id[0].id, "company_id": wiz.company_id.id }) journal_id = journal_id[0].id # Search for inventory sequence for fixed asset, if doesn't # exist create it inv_sequence_id = self.env['ir.sequence'].search([ ('name', '=', 'Inventar Mijloace Fixe'), ('company_id', '=', wiz.company_id.id) ]) if not inv_sequence_id: inv_sequence_id = self.env['ir.sequence'].create({ "name": 'Inventar Mijloace Fixe', "padding": 6, "implementation": 'no_gap', "number_next": 1, "number_increment": 1, "prefix": 'INV/', "company_id": wiz.company_id.id }) inv_sequence_id = inv_sequence_id[0].id f = open(os.path.join(data_dir, 'categoriiactive.csv'), 'rb') try: categorii = csv.DictReader(f) # id,parent_id,code,name,type,asset_type,method_number_min,method_number,account_asset_id,account_depreciation_id,account_expense_id,account_income_id,method,method_time,method_period for row in categorii: categ = categ_obj.search([ ('code', '=', row['code']), ('company_id', '=', wiz.company_id.id) ]) if not categ: if row['parent_code']: parent_category_id = categ_obj.search([ ('code', '=', row['parent_code']), ('company_id', '=', wiz.company_id.id) ]) if parent_category_id: parent_category_id = parent_category_id[ 0].id else: parent_category_id = False else: parent_category_id = False if row['type'] == 'normal': account_asset_id = account_obj.search([ ('code', '=', row['account_asset_id']), ('company_id', '=', wiz.company_id.id) ]) account_depreciation_id = account_obj.search( [('code', '=', row['account_depreciation_id']), ('company_id', '=', wiz.company_id.id) ]) account_expense_id = account_obj.search([ ('code', '=', row['account_expense_id']), ('company_id', '=', wiz.company_id.id) ]) account_income_id = account_obj.search([ ('code', '=', row['account_income_id']), ('company_id', '=', wiz.company_id.id) ]) categ = categ_obj.create({ 'parent_id': parent_category_id, 'code': row['code'], 'name': row['name'], 'type': row['type'], 'asset_type': row['asset_type'], 'method_number_min': row['method_number_min'], 'method_number': row['method_number'], 'sequence_id': row['asset_type'] == 'fixed' and inv_sequence_id or False, 'account_asset_id': account_asset_id and account_asset_id[0].id or False, 'account_depreciation_id': account_depreciation_id and account_depreciation_id[0].id or False, 'account_expense_depreciation_id': account_expense_id and account_expense_id[0].id or False, 'account_income_id': account_income_id and account_income_id[0].id or False, 'method': row['method'], 'method_time': row['method_time'], 'method_period': row['method_period'] }) else: categ = categ_obj.create({ 'parent_id': parent_category_id, 'code': row['code'], 'name': row['name'], 'type': row['type'], 'asset_type': row['asset_type'], }) finally: f.close() # Load Bank Statement Operation Templates installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_account_bank_statement'), ('state', '=', 'installed') ]) if installed: statement_obj = self.env['account.statement.operation.template'] wiz = self[0] if wiz.bank_statement_template_installed: statements = statement_obj.search([('company_id', '=', wiz.company_id.id)]) if not statements: f = open( os.path.join( data_dir, 'account_statement_operation_template.csv'), 'rb') try: operations = csv.DictReader(f) for row in operations: account_id = account_obj.search([ ('code', '=', row['account_id']), ('company_id', '=', wiz.company_id.id) ]) if account_id: statement_obj.create({ 'label': row['label'], 'name': row['name'], 'account_id': account_id[0].id, 'amount_type': row['amount_type'], 'amount': row['amount'], 'company_id': wiz.company_id.id, }) finally: f.close() # Load Account Period Templates installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_account_period_close'), ('state', '=', 'installed') ]) if installed: closing_obj = self.env['account.period.closing'] wiz = self[0] if wiz.account_period_close_template_installed: closings = closing_obj.search([('company_id', '=', wiz.company_id.id)]) if not closings: f = open( os.path.join(data_dir, 'account_period_close_templates.csv'), 'rb') try: operations = csv.DictReader(f) for row in operations: debit_account_id = account_obj.search([ ('code', '=', row['debit_account_id']), ('company_id', '=', wiz.company_id.id) ]) credit_account_id = account_obj.search([ ('code', '=', row['credit_account_id']), ('company_id', '=', wiz.company_id.id) ]) new_accounts = [] if row['account_ids']: accounts = row['account_ids'].split(",") for account in accounts: comp_account = account_obj.search([ ('code', '=', account), ('company_id', '=', wiz.company_id.id) ]) if comp_account: new_accounts.append(comp_account[0].id) if debit_account_id and credit_account_id: template = closing_obj.create({ 'name': row['name'], 'debit_account_id': debit_account_id[0].id, 'credit_account_id': credit_account_id[0].id, 'type': row['type'], 'account_ids': [(6, 0, new_accounts)], 'company_id': wiz.company_id.id, }) if row['type'] in ('income', 'expense'): template._onchange_type() finally: f.close() return res
def execute(self): self.ensure_one() res = super(ResConfigSettings, self).execute() data_dir = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'examples') # Load SIRUTA datas if field is checked if self.siruta_update: # First check if module is installed installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_siruta'), ('state', '=', 'installed') ]) if installed: path = data_dir + '/l10n_ro_siruta/' files = [ 'res.country.zone.csv', 'res.country.state.csv', 'res.country.commune.csv', 'res.city.csv' ] for file1 in files: with tools.file_open(path + file1) as fdata: tools.convert_csv_import(self._cr, 'l10n_ro_config', file1, bytes(fdata.read(), 'utf-8'), {}, mode="init", noupdate=True) # Load HR Job datas if field is checked if self.hr_job_update: # First check if module is installed installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_hr'), ('state', '=', 'installed') ]) if installed: path = data_dir + '/l10n_ro_hr/' files = ['hr.job.csv'] for file1 in files: with tools.file_open(path + file1) as fdata: tools.convert_csv_import(self._cr, 'l10n_ro_config', file1, bytes(fdata.read(), 'utf-8'), {}, mode="init", noupdate=True) # Load SIRUTA datas if field is checked if self.caen_update: # First check if module is installed installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_hr_contract'), ('state', '=', 'installed') ]) if installed: path = data_dir + '/l10n_ro_hr/' files = ['res.company.caen.csv'] for file1 in files: with tools.file_open(path + file1) as fdata: tools.convert_csv_import(self._cr, 'l10n_ro_config', file1, bytes(fdata.read(), 'utf-8'), {}, mode="init", noupdate=True) # Load Medical Leaves datas if field is checked if self.medical_update: # First check if module is installed installed = self.env['ir.module.module'].search([ ('name', '=', 'l10n_ro_hr_medical_holidays'), ('state', '=', 'installed') ]) if installed: path = data_dir + '/l10n_ro_hr_medical_holidays/' files = [ 'hr.holidays.status.csv', 'hr.medical.disease.csv', 'hr.medical.emergency.disease.csv', 'hr.medical.infecto.disease.csv' ] for file1 in files: with tools.file_open(path + file1) as fdata: tools.convert_csv_import(self._cr, 'l10n_ro_config', file1, bytes(fdata.read(), 'utf-8'), {}, mode="init", noupdate=True) return res