def test_account_bank_statement_def(self): """ In order to test Bank Statement feature of account I create a bank statement line and confirm it and check it's move created """ tools.convert_file(self.cr, 'account', get_resource_path('account', 'test', 'account_minimal_test.xml'), {}, 'init', False, 'test', self.registry._assertion_report) # Select the period and journal for the bank statement journal = self.env['account.bank.statement'].with_context({ 'lang': u'en_US', 'tz': False, 'active_model': 'ir.ui.menu', 'journal_type': 'bank', 'date': time.strftime("%Y/%m/%d") })._default_journal() self.assertTrue(journal, 'Journal has not been selected') # Create a bank statement with Opening and Closing balance 0 account_statement = self.env['account.bank.statement'].create({ 'balance_end_real': 0.0, 'balance_start': 0.0, 'date': time.strftime("%Y-%m-%d"), 'company_id': self.ref('base.main_company'), 'journal_id': journal.id, }) # Create Account bank statement line account_bank_statement_line = self.env['account.bank.statement.line'].create({ 'amount': 1000, 'date': time.strftime('%Y-%m-%d'), 'partner_id': self.ref('base.res_partner_4'), 'name': 'EXT001', 'statement_id': account_statement.id, }) # Create a Account for bank statement line process account = self.env['account.account'].create({ 'name': 'toto', 'code': 'bidule', 'user_type_id': self.ref('account.data_account_type_fixed_assets'), }) # Process the bank statement line account_statement.line_ids.process_reconciliation(new_aml_dicts=[{ 'credit': 1000, 'debit': 0, 'name': 'toto', 'account_id': account.id, }]) # Modify the bank statement and set the Closing Balance 1000. account_statement.write({'balance_end_real': 1000.00}) # Confirm the bank statement using Confirm button account_statement.button_confirm_bank() # Check bank statement state should be confirm self.assertEquals(account_statement.state, 'confirm')
def import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) values = self.get_values_from_terp(terp) unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: raise UserError(_("Unmet module dependencies: %s") % ', '.join(unmet_dependencies)) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: _logger.info("module %s: loading %s", module, filename) noupdate = False if filename.endswith('.csv') and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'r') as fp: data = fp.read().encode('base64') url_path = '/%s%s' % (module, full_path.split(path)[1].replace(os.path.sep, '/')) url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def load_data(cr, idref, mode, kind, package, report): """ 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. """ def _get_files_of_kind(kind): if kind == 'demo': kind = ['demo_xml', 'demo'] elif kind == 'data': kind = ['init_xml', 'update_xml', 'data'] if isinstance(kind, str): kind = [kind] files = [] for k in kind: for f in package.data[k]: files.append(f) if k.endswith('_xml') and not (k == 'init_xml' and not f.endswith('.xml')): # init_xml, update_xml and demo_xml are deprecated except # for the case of init_xml with csv and sql files as # we can't specify noupdate for those file. correct_key = 'demo' if k.count('demo') else 'data' _logger.warning( "module %s: key '%s' is deprecated in favor of '%s' for file '%s'.", package.name, k, correct_key, f ) return files try: if kind in ('demo', 'test'): threading.currentThread().testing = True for filename in _get_files_of_kind(kind): _logger.info("loading %s/%s", package.name, filename) noupdate = False if kind in ('demo', 'demo_xml') or (filename.endswith('.csv') and kind in ('init', 'init_xml')): noupdate = True tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report) finally: if kind in ('demo', 'test'): threading.currentThread().testing = False
def test_product_margin(self): ''' In order to test the product_margin module ''' # load account_minimal_test.xml file for chart of account in configuration tools.convert_file(self.cr, 'product_margin', get_resource_path('account', 'test', 'account_minimal_test.xml'), {}, 'init', False, 'test', self.registry._assertion_report) supplier = self.env['res.partner'].create({'name': 'Supplier', 'supplier': True}) customer = self.env['res.partner'].create({'name': 'Customer', 'customer': True}) ipad = self.env.ref("product.product_product_4") # Create supplier invoice and customer invoice to test product margin. # Define supplier invoices self.create_account_invoice('in_invoice', supplier, ipad, 10.0, 300.00) self.create_account_invoice('in_invoice', supplier, ipad, 4.0, 450.00) # Define Customer Invoices self.create_account_invoice('out_invoice', customer, ipad, 20.0, 750.00) self.create_account_invoice('out_invoice', customer, ipad, 10.0, 550.00) result = ipad._compute_product_margin_fields_values() # Sale turnover ( Quantity * Price Subtotal / Quantity) sale_turnover = ((20.0 * 750.00) + (10.0 * 550.00)) # Expected sale (Total quantity * Sale price) sale_expected = (750.00 * 30.0) # Purchase total cost (Quantity * Unit price) purchase_total_cost = ((10.0 * 300.00) + (4.0 * 450.00)) # Purchase normal cost ( Total quantity * Cost price) purchase_normal_cost = (14.0 * 500.00) total_margin = sale_turnover - purchase_total_cost expected_margin = sale_expected - purchase_normal_cost # Check total margin self.assertEqual(result[ipad.id]['total_margin'], total_margin, "Wrong Total Margin.") # Check expected margin self.assertEqual(result[ipad.id]['expected_margin'], expected_margin, "Wrong Expected Margin.")
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. """ try: if kind in ('demo', 'test'): threading.currentThread().testing = True for filename in _get_files_of_kind(kind): _logger.info("loading %s/%s", module_name, filename) noupdate = False if kind in ('demo', 'demo_xml') or (filename.endswith('.csv') and kind in ('init', 'init_xml')): noupdate = True tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report) finally: if kind in ('demo', 'test'): threading.currentThread().testing = False
def uninstall_hook(cr, registry): convert_file(cr, "l10n_ro_payment_receipt_report", "payment_receipt_report_restore.xml", None)
def _load(self, module, *args): tools.convert_file(self.cr, 'website', get_module_resource(module, *args), {}, 'init', False, 'test')
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) values = self.get_values_from_terp(terp) unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: if (unmet_dependencies == set(['web_studio']) and _is_studio_custom(path)): err = _("Studio customizations require Studio") else: err = _("Unmet module dependencies: %s") % ', '.join( unmet_dependencies, ) raise UserError(err) elif 'web_studio' not in installed_mods and _is_studio_custom(path): raise UserError(_("Studio customizations require Studio")) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if ext == '.csv' and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/{}{}'.format(module, full_path.split(path)[1].replace(os.path.sep, '/')) if not isinstance(url_path, pycompat.text_type): url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def _load(cls, module, *args): convert_file( cls.cr, "purchase_sale_inter_company", get_resource_path(module, *args), {}, 'init', False, 'test', cls.registry._assertion_report, )
def _load(self, module, *args): tools.convert_file(self.cr, 'account_asset', get_resource_path(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _load(self, module, *args): tools.convert_file(self.cr, 'hr_payroll_account_community', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) values = self.get_values_from_terp(terp) if 'version' in terp: values['latest_version'] = terp['version'] unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: if (unmet_dependencies == set(['web_studio']) and _is_studio_custom(path)): err = _("Studio customizations require Studio") else: err = _("Unmet module dependencies: %s") % ', '.join( unmet_dependencies, ) raise UserError(err) elif 'web_studio' not in installed_mods and _is_studio_custom(path): raise UserError(_("Studio customizations require the Odoo Studio app.")) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if ext == '.csv' and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/{}{}'.format(module, full_path.split(path)[1].replace(os.path.sep, '/')) if not isinstance(url_path, str): url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def _load(self, module, *args): tools.convert_file(self.cr, 'report_intrastat', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def test_account_bank_statement_def(self): """ In order to test Bank Statement feature of account I create a bank statement line and confirm it and check it's move created """ tools.convert_file( self.cr, 'account', get_resource_path('account', 'test', 'account_minimal_test.xml'), {}, 'init', False, 'test', self.registry._assertion_report) # Select the period and journal for the bank statement journal = self.env['account.bank.statement'].with_context({ 'lang': u'en_US', 'tz': False, 'active_model': 'ir.ui.menu', 'journal_type': 'bank', 'date': time.strftime("%Y/%m/%d") })._default_journal() self.assertTrue(journal, 'Journal has not been selected') # Create a bank statement with Opening and Closing balance 0 account_statement = self.env['account.bank.statement'].create({ 'balance_end_real': 0.0, 'balance_start': 0.0, 'date': time.strftime("%Y-%m-%d"), 'company_id': self.ref('base.main_company'), 'journal_id': journal.id, }) # Create Account bank statement line account_bank_statement_line = self.env[ 'account.bank.statement.line'].create({ 'amount': 1000, 'date': time.strftime('%Y-%m-%d'), 'partner_id': self.ref('base.res_partner_4'), 'name': 'EXT001', 'statement_id': account_statement.id, }) # Create a Account for bank statement line process account = self.env['account.account'].create({ 'name': 'toto', 'code': 'bidule', 'user_type_id': self.ref('account.data_account_type_fixed_assets'), }) # Process the bank statement line account_statement.line_ids.process_reconciliation( new_aml_dicts=[{ 'credit': 1000, 'debit': 0, 'name': 'toto', 'account_id': account.id, }]) # Modify the bank statement and set the Closing Balance 1000. account_statement.write({'balance_end_real': 1000.00}) # Confirm the bank statement using Confirm button account_statement.button_confirm_bank() # Check bank statement state should be confirm self.assertEquals(account_statement.state, 'confirm')
def setUpClass(cls): super(TestAccountPayment, cls).setUpClass() module = "account_payment_other_company" convert_file( cls.cr, module, get_resource_path(module, "tests", "test_account_payment_data.xml"), None, 'init', False, 'test', cls.registry._assertion_report, ) cls.account_obj = cls.env['account.account'] cls.invoice_obj = cls.env.ref( 'account_payment_other_company.customer_invoice_company_a') cls.vendor_bill_obj = cls.env.ref( 'account_payment_other_company.vendor_bill_company_a') cls.company_a = cls.env.ref('account_payment_other_company.company_a') cls.company_b = cls.env.ref('account_payment_other_company.company_b') cls.account_payment_obj = cls.env['account.payment'] cls.journal_1 = cls.env['account.journal'] cls.journal_2 = cls.env['account.journal'] cls.account_dt1 = cls.env['account.account'] cls.account_dt2 = cls.env['account.account'] cls.account_df1 = cls.env['account.account'] cls.account_d21 = cls.env['account.account'] cls.company_a.due_fromto_payment_journal_id = cls.env.ref( 'account_payment_other_company.sales_journal_company_a') cls.company_a.due_fromto_payment_journal_id.update_posted = True cls.company_b.due_fromto_payment_journal_id = cls.env.ref( 'account_payment_other_company.bank_journal_company_b') cls.company_b.due_fromto_payment_journal_id.\ default_debit_account_id = cls.env.ref( 'account_payment_other_company.a_expense_company_b' ) cls.company_a.due_from_account_id = cls.env.ref( 'account_payment_other_company.a_pay_company_a') cls.company_a.due_to_account_id = cls.env.ref( 'account_payment_other_company.a_recv_company_a') cls.company_b.due_from_account_id = cls.env.ref( 'account_payment_other_company.a_recv_company_b') cls.company_b.due_to_account_id = cls.env.ref( 'account_payment_other_company.a_pay_company_b') cls.company_a_journal = cls.env.\ ref('account_payment_other_company.bank_journal_company_a') cls.company_b_journal = cls.env.\ ref('account_payment_other_company.bank_journal_company_b') cls.company_b_journal.update_posted = True cls.chart = cls.env['account.chart.template'].search([], limit=1) if not cls.chart: raise ValidationError( # translation to avoid pylint warnings _("No Chart of Account Template has been defined !"))
def _load(self, module, *args): tools.convert_file(self.cr, 'l10n_ro_account_period_close', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def setUp(self): super(TestCurrencyReevaluation, self).setUp() ref = self.env.ref self.per_close_model = self.env["account.period.closing"] self.wiz_close_model = self.env["account.period.closing.wizard"] # load account_minimal_test.xml file for chart of account in configuration tools.convert_file( self.cr, "l10n_ro_account_period_close", get_resource_path("account", "test", "account_minimal_test.xml"), {}, "init", False, "test", self.registry._assertion_report, ) company = self.env.user.company_id search_account = self.env["account.account"].search type_revenue = self.env.ref("account.data_account_type_revenue") default_account_revenue = search_account( [("company_id", "=", company.id), ("user_type_id", "=", type_revenue.id)], limit=1, ) type_expenses = self.env.ref("account.data_account_type_expenses") default_account_expense = search_account( [("company_id", "=", company.id), ("user_type_id", "=", type_expenses.id)], limit=1, ) default_account_receivable = search_account( [("company_id", "=", company.id), ("user_type_id.type", "=", "receivable")], limit=1, ) default_account_payable = search_account( [("company_id", "=", company.id), ("user_type_id.type", "=", "payable")], limit=1, ) default_account_tax_sale = company.account_sale_tax_id.mapped( "invoice_repartition_line_ids.account_id") default_account_tax_purchase = company.account_purchase_tax_id.mapped( "invoice_repartition_line_ids.account_id") self.test_move = self.env["account.move"].create({ "type": "entry", "date": fields.Date.from_string(time.strftime("%Y-%m") + "-01"), "line_ids": [ ( 0, None, { "name": "revenue line 2", "account_id": default_account_revenue.id, "debit": 0.0, "credit": 1000.0, "tax_ids": [(6, 0, company.account_sale_tax_id.ids)], }, ), ( 0, None, { "name": "tax line", "account_id": default_account_tax_sale.id, "debit": 0.0, "credit": 150.0, }, ), ( 0, None, { "name": "client line", "account_id": default_account_receivable.id, "debit": 1150, "credit": 0.0, }, ), ], }) self.test_move.action_post() self.test_move = self.env["account.move"].create({ "type": "entry", "date": fields.Date.from_string(time.strftime("%Y-%m") + "-01"), "line_ids": [ ( 0, None, { "name": "cost line 2", "account_id": default_account_expense.id, "debit": 100.0, "credit": 0.0, "tax_ids": [(6, 0, company.account_purchase_tax_id.ids)], }, ), ( 0, None, { "name": "tax line", "account_id": default_account_tax_purchase.id, "debit": 15.0, "credit": 0.0, }, ), ( 0, None, { "name": "ventor line", "account_id": default_account_payable.id, "debit": 0.0, "credit": 115.0, }, ), ], }) self.test_move.action_post() self.misc_journal = ref( "l10n_ro_account_period_close.miscellaneous_journal") self.debit_acc = ref( "l10n_ro_account_period_close.current_liabilities") self.credit_acc = ref( "l10n_ro_account_period_close.current_liabilities") self.vat_paid = ref("l10n_ro_account_period_close.ova") self.vat_received = ref("l10n_ro_account_period_close.iva") self.vat_close_debit = ref("l10n_ro_account_period_close.cas") self.vat_close_credit = ref( "l10n_ro_account_period_close.current_liabilities") self.exp_closing = self.per_close_model.create({ "name": "Closing Expenses", "type": "expense", "journal_id": self.misc_journal.id, "debit_account_id": self.debit_acc.id, "credit_account_id": self.credit_acc.id, }) self.inc_closing = self.per_close_model.create({ "name": "Closing Incomes", "type": "income", "journal_id": self.misc_journal.id, "close_result": True, "debit_account_id": self.debit_acc.id, "credit_account_id": self.credit_acc.id, }) self.vat_closing = self.per_close_model.create({ "name": "Closing VAT", "type": "selected", "account_ids": [(6, 0, [self.vat_paid.id, self.vat_received.id])], "journal_id": self.misc_journal.id, "debit_account_id": self.vat_close_debit.id, "credit_account_id": self.vat_close_credit.id, })
def post_init_hook(cr, registry): """Import XML data to change core data""" env = api.Environment(cr, SUPERUSER_ID, {}) files = [ "data/l10n_br_fiscal.cnae.csv", "data/l10n_br_fiscal.cfop.csv", "data/l10n_br_fiscal_cfop_data.xml", "data/l10n_br_fiscal.tax.ipi.control.seal.csv", "data/l10n_br_fiscal.tax.ipi.guideline.csv", "data/l10n_br_fiscal.tax.ipi.guideline.class.csv", "data/l10n_br_fiscal.tax.pis.cofins.base.csv", "data/l10n_br_fiscal.tax.pis.cofins.credit.csv", "data/l10n_br_fiscal.service.type.csv", "data/simplified_tax_data.xml", "data/operation_data.xml", "data/l10n_br_fiscal_tax_icms_data.xml", ] _logger.info( _("Loading l10n_br_fiscal fiscal files. It may take a minute...")) for file in files: tools.convert_file( cr, "l10n_br_fiscal", file, None, mode="init", noupdate=True, kind="init", report=None, ) if not tools.config["without_demo"]: demofiles = [ "demo/l10n_br_fiscal.ncm-demo.csv", "demo/l10n_br_fiscal.nbm-demo.csv", "demo/l10n_br_fiscal.nbs-demo.csv", "demo/l10n_br_fiscal.cest-demo.csv", "demo/city_taxation_code_demo.xml", "demo/company_demo.xml", "demo/product_demo.xml", "demo/partner_demo.xml", "demo/fiscal_document_demo.xml", "demo/fiscal_operation_demo.xml", "demo/subsequent_operation_demo.xml", "demo/l10n_br_fiscal_document_email.xml", "demo/fiscal_document_nfse_demo.xml", "demo/res_users_demo.xml", ] # Load only demo CSV files with few lines instead of thousands # unless a flag mention the contrary if tools.config.get("load_ncm"): demofiles.append("data/l10n_br_fiscal.ncm.csv") if tools.config.get("load_nbm"): demofiles.append("data/l10n_br_fiscal.nbm.csv") if tools.config.get("load_nbs"): demofiles.append("data/l10n_br_fiscal.nbs.csv") if not tools.config.get("load_cest"): demofiles.append("data/l10n_br_fiscal.cest.csv") _logger.info(_("Loading l10n_br_fiscal demo files.")) for f in demofiles: tools.convert_file( cr, "l10n_br_fiscal", f, None, mode="init", noupdate=True, kind="demo", report=None, ) companies = [ env.ref('base.main_company', raise_if_not_found=False), env.ref('l10n_br_base.empresa_lucro_presumido', raise_if_not_found=False), env.ref('l10n_br_base.empresa_simples_nacional', raise_if_not_found=False), ] for company in companies: l10n_br_fiscal_certificate_id = env["l10n_br_fiscal.certificate"] company.certificate_nfe_id = l10n_br_fiscal_certificate_id.create( misc.prepare_fake_certificate_vals()) company.certificate_ecnpj_id = l10n_br_fiscal_certificate_id.create( misc.prepare_fake_certificate_vals( cert_type=CERTIFICATE_TYPE_ECNPJ)) elif tools.config["without_demo"]: prodfiles = [] # Load full CSV files with few lines unless a flag # mention the contrary if not tools.config.get("skip_ncm"): prodfiles.append("data/l10n_br_fiscal.ncm.csv") if not tools.config.get("skip_nbm"): prodfiles.append("data/l10n_br_fiscal.nbm.csv") if not tools.config.get("skip_nbs"): prodfiles.append("data/l10n_br_fiscal.nbs.csv") if not tools.config.get("skip_cest"): prodfiles.append("data/l10n_br_fiscal.cest.csv") _logger.info( _("Loading l10n_br_fiscal production files. It may take at least" " 3 minutes...")) for f in prodfiles: tools.convert_file( cr, "l10n_br_fiscal", f, None, mode="init", noupdate=True, kind="init", report=None, ) # Load post files posloadfiles = [ "data/l10n_br_fiscal_icms_tax_definition_data.xml", ] _logger.info( _("Loading l10n_br_fiscal post init files. It may take a minute...")) for file in posloadfiles: tools.convert_file( cr, "l10n_br_fiscal", file, None, mode="init", noupdate=True, kind="init", report=None, )
def _load(cls, module, *args): convert_file(cls.cr, 'ag_dms', get_module_resource(module, *args), {}, 'init', False, 'test', cls.registry._assertion_report)
def _load(self, module, *args): tools.convert_file( self.cr, 'hr_payroll_account', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _load_xml(cls, module, filepath): tools.convert_file( cls.cr, module, get_resource_path(module, filepath), {}, mode='init', noupdate=False, kind='test')
def _load(self, module, *args): tools.convert_file(self.cr, 'stock_dropshipping', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def post_init_hook(cr, registry): env = api.Environment(cr, SUPERUSER_ID, {}) _logger.info(_("Preparing datas for 'band_booking'...")) # Delete unused native datas # ========================== def _unlink_data(model, module, file_path): data_elements = etree.parse(file_open(file_path)) model_elements = data_elements.xpath( "//record[@model='{}']".format(model)) to_unlink = env["{}".format(model)] for el in model_elements: el_xmlid = "{}.".format(module) + el.get("id") try: to_unlink |= env.ref(el_xmlid) except ValueError: continue to_unlink.unlink() # Delete native lost reasons _unlink_data("crm.lost.reason", "crm", "crm/data/crm_data.xml") # Delete native crm stages _unlink_data("crm.stage", "crm", "crm/data/crm_stage_data.xml") # Add all the users do 'group_use_lead' in order to display Leads for everybody # ============================================================================= users = env["res.users"].search([("id", "!=", env.ref("base.public_user").id)]) group_use_lead = env.ref("crm.group_use_lead") group_use_lead.users = [(6, 0, users.ids)] # Load demo records # ================= if tools.config.get("demo_booking"): _logger.info(_("Loading demo datas for 'band_booking'...")) files = [ "demo/res.partner-festival-demo.csv", "demo/res.partner-venue-demo.csv", "demo/res.partner-contact-demo.csv", ] for file in files: tools.convert_file( cr, "band_booking", file, None, mode="init", noupdate=True, kind="init", report=None, ) image_folder = "./odoo/external-src/band-booking/band_booking/static/img/" image_files = {} for file_name in listdir(image_folder): # To load a demo image, its name must be in the format "xml_id-demo.ext" if path.splitext(file_name)[0].split("-")[1] == "demo": image_files[file_name.split("-")[0]] = image_folder + file_name for name, img_path in image_files.items(): with open(img_path, "rb") as image_file: partner = env.ref("band_booking.{}".format(name)) partner.image = base64.b64encode(image_file.read())
def _load(self, module, *args): tools.convert_file(self.cr, 'l10n_ch_scan_bvr', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def post_init_hook(cr, registry): """Import XML data to change core data""" files = [ "data/l10n_br_fiscal.cnae.csv", "data/l10n_br_fiscal.cfop.csv", "data/l10n_br_fiscal_cfop_data.xml", "data/l10n_br_fiscal.tax.ipi.control.seal.csv", "data/l10n_br_fiscal.tax.ipi.guideline.csv", "data/l10n_br_fiscal.tax.ipi.guideline.class.csv", "data/l10n_br_fiscal.tax.pis.cofins.base.csv", "data/l10n_br_fiscal.tax.pis.cofins.credit.csv", "data/l10n_br_fiscal.service.type.csv", "data/simplified_tax_data.xml", "data/operation_data.xml", "data/l10n_br_fiscal_tax_icms_data.xml", ] _logger.info( _("Loading l10n_br_fiscal fiscal files. It may take a minute...")) for file in files: tools.convert_file( cr, "l10n_br_fiscal", file, None, mode="init", noupdate=True, kind="init", report=None, ) if not tools.config["without_demo"]: demofiles = [ "demo/l10n_br_fiscal.ncm-demo.csv", "demo/l10n_br_fiscal.nbm-demo.csv", "demo/l10n_br_fiscal.nbs-demo.csv", "demo/l10n_br_fiscal.cest-demo.csv", "demo/company_demo.xml", "demo/product_demo.xml", "demo/partner_demo.xml", "demo/fiscal_document_demo.xml", "demo/fiscal_operation_demo.xml", "demo/subsequent_operation_demo.xml", "demo/l10n_br_fiscal_document_email.xml", "demo/city_taxation_code_demo.xml", ] # Load only demo CSV files with few lines instead of thousands # unless a flag mention the contrary if tools.config.get("load_ncm"): demofiles.append("data/l10n_br_fiscal.ncm.csv") if tools.config.get("load_nbm"): demofiles.append("data/l10n_br_fiscal.nbm.csv") if tools.config.get("load_nbs"): demofiles.append("data/l10n_br_fiscal.nbs.csv") if not tools.config.get("load_cest"): demofiles.append("data/l10n_br_fiscal.cest.csv") _logger.info(_("Loading l10n_br_fiscal demo files.")) for f in demofiles: tools.convert_file( cr, "l10n_br_fiscal", f, None, mode="init", noupdate=True, kind="demo", report=None, ) elif tools.config["without_demo"]: prodfiles = [] # Load full CSV files with few lines unless a flag # mention the contrary if not tools.config.get("skip_ncm"): prodfiles.append("data/l10n_br_fiscal.ncm.csv") if not tools.config.get("skip_nbm"): prodfiles.append("data/l10n_br_fiscal.nbm.csv") if not tools.config.get("skip_nbs"): prodfiles.append("data/l10n_br_fiscal.nbs.csv") if not tools.config.get("skip_cest"): prodfiles.append("data/l10n_br_fiscal.cest.csv") _logger.info( _("Loading l10n_br_fiscal production files. It may take at least" " 3 minutes...")) for f in prodfiles: tools.convert_file( cr, "l10n_br_fiscal", f, None, mode="init", noupdate=True, kind="init", report=None, ) # Load post files posloadfiles = [ "data/l10n_br_fiscal_icms_tax_definition_data.xml", ] _logger.info( _("Loading l10n_br_fiscal post init files. It may take a minute...")) for file in posloadfiles: tools.convert_file( cr, "l10n_br_fiscal", file, None, mode="init", noupdate=True, kind="init", report=None, )
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_manifest(module, mod_path=path) if not terp: return False values = self.get_values_from_terp(terp) if 'version' in terp: values['latest_version'] = terp['version'] unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: if (unmet_dependencies == set(['web_studio']) and _is_studio_custom(path)): err = _("Studio customizations require Studio") else: err = _("Unmet module dependencies: \n\n - %s") % '\n - '.join( known_mods.filtered(lambda mod: mod.name in unmet_dependencies).mapped('shortdesc') ) raise UserError(err) elif 'web_studio' not in installed_mods and _is_studio_custom(path): raise UserError(_("Studio customizations require the Odoo Studio app.")) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if ext == '.csv' and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/{}{}'.format(module, full_path.split(path)[1].replace(os.path.sep, '/')) if not isinstance(url_path, str): url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: attachment = IrAttachment.create(values) self.env['ir.model.data'].create({ 'name': f"attachment_{url_path}".replace('.', '_'), 'model': 'ir.attachment', 'module': module, 'res_id': attachment.id, }) IrAsset = self.env['ir.asset'] assets_vals = [] # Generate 'ir.asset' record values for each asset delared in the manifest for bundle, commands in terp.get('assets', {}).items(): for command in commands: directive, target, path = IrAsset._process_command(command) path = path if path.startswith('/') else '/' + path # Ensures a '/' at the start assets_vals.append({ 'name': f'{module}.{bundle}.{path}', 'directive': directive, 'target': target, 'path': path, 'bundle': bundle, }) # Look for existing assets existing_assets = { asset.name: asset for asset in IrAsset.search([('name', 'in', [vals['name'] for vals in assets_vals])]) } assets_to_create = [] # Update existing assets and generate the list of new assets values for values in assets_vals: if values['name'] in existing_assets: existing_assets[values['name']].write(values) else: assets_to_create.append(values) # Create new assets and attach 'ir.model.data' records to them created_assets = IrAsset.create(assets_to_create) self.env['ir.model.data'].create([{ 'name': f"{asset['bundle']}_{asset['path']}".replace(".", "_"), 'model': 'ir.asset', 'module': module, 'res_id': asset.id, } for asset in created_assets]) return True
def setUpClass(cls): super(TestConsolidatedInvoice, cls).setUpClass() module = "account_invoice_consolidated" convert_file( cls.cr, module, get_resource_path(module, "tests", "test_consolidated_invoices_data.xml"), None, 'init', False, 'test', cls.registry._assertion_report, ) cls.partner_user = cls.env.\ ref('account_invoice_consolidated.partner_user_a') cls.consolidated_inv_obj = cls.env['account.invoice.consolidated'] cls.account_obj = cls.env['account.account'] cls.invoice_obj_a = cls.env.ref( 'account_invoice_consolidated.customer_invoice_company_a') cls.invoice_obj_a.partner_id = cls.partner_user cls.invoice_obj_a.date_invoice = date.\ today() + relativedelta(months=-3) cls.invoice_obj_a.sudo().action_invoice_open() cls.invoice_obj_b = cls.env.ref( 'account_invoice_consolidated.customer_invoice_company_b') cls.invoice_obj_b.partner_id = cls.partner_user cls.invoice_obj_b.date_invoice = date.\ today() + relativedelta(months=-3) cls.invoice_obj_b.sudo().action_invoice_open() cls.company_a = cls.env.ref('account_invoice_consolidated.company_a') cls.company_b = cls.env.ref('account_invoice_consolidated.company_b') cls.env.user.company_id = cls.company_a cls.journal_1 = cls.env['account.journal'] cls.journal_2 = cls.env['account.journal'] cls.account_dt1 = cls.env['account.account'] cls.account_dt2 = cls.env['account.account'] cls.account_df1 = cls.env['account.account'] cls.account_d21 = cls.env['account.account'] cls.company_a.due_fromto_payment_journal_id = cls.env.ref( 'account_invoice_consolidated.sales_journal_company_a') cls.company_b.due_fromto_payment_journal_id = cls.env.ref( 'account_invoice_consolidated.bank_journal_company_b') cls.company_b.due_fromto_payment_journal_id.\ default_debit_account_id = cls.env.ref( 'account_invoice_consolidated.a_expense_company_b' ) cls.company_a.due_from_account_id = cls.env.ref( 'account_invoice_consolidated.a_pay_company_a') cls.company_a.due_to_account_id = cls.env.ref( 'account_invoice_consolidated.a_recv_company_a') cls.company_b.due_from_account_id = cls.env.ref( 'account_invoice_consolidated.a_recv_company_b') cls.company_b.due_to_account_id = cls.env.ref( 'account_invoice_consolidated.a_pay_company_b') cls.company_a_journal = cls.env.\ ref('account_invoice_consolidated.bank_journal_company_a') cls.company_b_journal = cls.env.\ ref('account_invoice_consolidated.bank_journal_company_b') cls.chart = cls.env['account.chart.template'].search([], limit=1) if not cls.chart: raise ValidationError( # translation to avoid pylint warnings _("No Chart of Account Template has been defined !"))
def _load(self, module, *args): convert_file(self.cr, 'account', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _load(self, module, *args): convert_file(self.cr, 'account_spread_cost_revenue', get_resource_path(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _load(self, module, *args): tools.convert_file(self.cr, 'account_voucher', get_resource_path(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _uninstall_rebrand_system(cr, registry): if version_info[5] != 'e': filename = get_module_resource('base', 'data', 'ir_module_module.xml') convert_file(cr, 'base', filename, {}, 'init', False, 'data', registry._assertion_report)
def pre_init_hook(cr): convert_file( cr, 'l10n_mx_edi_hr_expense', 'data/partner_tags.xml', {}, 'init', True, 'data', False)
def _load(cls, module, *args): tools.convert_file(cls.cr, module, get_resource_path(module, *args), {}, 'init', False, 'test', cls.registry._assertion_report)
def _load(self, module, *args): tools.convert_file( self.cr, 'stock_dropshipping', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _load(self, module, *args): convert_file(self.cr, 'l10n_de', get_resource_path(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def setUpClass(cls): super().setUpClass() cls.company_a = cls.env.ref("base.main_company") tools.convert_file( cls.cr, "account", get_resource_path("account", "test", "account_minimal_test.xml"), {}, "init", False, "test", ) cls.account_move_obj = cls.env["account.move"] cls.account_move_line_obj = cls.env["account.move.line"] cls.cnab_log_obj = cls.env["l10n_br_cnab.return.log"] cls.account_id = cls.env.ref("account.a_recv") cls.bank_account = cls.env.ref("account.bnk") cls.import_wizard_obj = cls.env["credit.statement.import"] # Get Invoice for test cls.invoice_unicred_1 = cls.env.ref( "l10n_br_account_payment_order." "demo_invoice_payment_order_unicred_cnab400") cls.invoice_unicred_2 = cls.env.ref( "l10n_br_account_payment_brcobranca." "demo_invoice_brcobranca_unicred_cnab400") cls.invoice_ailos_1 = cls.env.ref( "l10n_br_account_payment_order." "demo_invoice_payment_order_ailos_cnab240") cls.journal = cls.env.ref( "l10n_br_account_payment_order.unicred_journal") # I validate invoice by creating on cls.invoice_unicred_1.action_invoice_open() cls.invoice_unicred_2.action_invoice_open() cls.invoice_ailos_1.action_invoice_open() # Para evitar erros nos testes de variação da Sequencia do # Nosso Numero/own_number quando se roda mais de uma vez ou # devido a diferença entre os comandos feitos pelo Travis cls.invoice_unicred_1_own_numbers = [] for line in cls.invoice_unicred_1.financial_move_line_ids: # No arquivo de retorno vem o NOSSO NUMERO + Digito Verificador cls.invoice_unicred_1_own_numbers.append(line.own_number + "0") cls.invoice_unicred_2_own_numbers = [] for line in cls.invoice_unicred_2.financial_move_line_ids: # No arquivo de retorno vem o NOSSO NUMERO + Digito Verificador cls.invoice_unicred_2_own_numbers.append(line.own_number + "0") cls.invoice_ailos_1_own_numbers = [] for line in cls.invoice_ailos_1.financial_move_line_ids: cls.invoice_ailos_1_own_numbers.append(line.own_number) payment_order = cls.env["account.payment.order"].search([ ("payment_mode_id", "=", cls.invoice_unicred_1.payment_mode_id.id) ]) # Open payment order payment_order.draft2open() # Verifica se deve testar com o mock if os.environ.get("CI"): # Generate file_name = get_resource_path( "l10n_br_account_payment_brcobranca", "tests", "data", "teste_remessa-unicred_400-1.REM", ) with open(file_name, "rb") as f: mocked_response = f.read() with mock.patch( _provider_class_pay_order + "._get_brcobranca_remessa", return_value=mocked_response, ): payment_order.open2generated() else: payment_order.open2generated() # Confirm Upload payment_order.generated2uploaded()