diff options
Diffstat (limited to 'addons/account/tests/common.py')
| -rw-r--r-- | addons/account/tests/common.py | 106 |
1 files changed, 66 insertions, 40 deletions
diff --git a/addons/account/tests/common.py b/addons/account/tests/common.py index e047303c0fb..a0c3d87fee2 100644 --- a/addons/account/tests/common.py +++ b/addons/account/tests/common.py @@ -133,6 +133,12 @@ class AccountTestCommon(SavepointCase): 'name': 'Opening Expense - (test)', 'user_type_id': cls.env.ref('account.data_account_type_expenses').id, }) + cls.sus = cls.env['account.account'].create({ + 'name': 'Suspense Account - (test)', + 'code': 'X1115', + 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id, + }) + cls.company.account_journal_suspense_account_id = cls.sus # Profit and Loss cls.income_fx_income = cls.env['account.account'].create({ @@ -238,16 +244,12 @@ class AccountTestCommon(SavepointCase): 'name': 'Vendor Bills - Test', 'code': 'TEXJ', 'type': 'purchase', - 'default_credit_account_id': cls.a_expense.id, - 'default_debit_account_id': cls.a_expense.id, 'refund_sequence': True, }) cls.bank_journal = cls.env['account.journal'].create({ 'name': 'Bank - Test', 'code': 'TBNK', 'type': 'bank', - 'default_credit_account_id': cls.bnk.id, - 'default_debit_account_id': cls.bnk.id, }) cls.cash_journal = cls.env['account.journal'].create({ 'name': 'Cash - Test', @@ -367,6 +369,12 @@ class AccountTestNoChartCommon(SavepointCaseWithUserDemo): 'code': 'SJT0', }) + cls.general_journal0 = cls.env['account.journal'].create({ + 'name': 'General Journal', + 'type': 'general', + 'code': 'GJT0', + }) + @classmethod def setUpAdditionalAccounts(cls): """ Set up some addionnal accounts: expenses, revenue, ... """ @@ -415,6 +423,12 @@ class AccountTestNoChartCommon(SavepointCaseWithUserDemo): 'type': 'general', 'company_id': cls.env.user.company_id.id, }) + cls.journal_bank = cls.env['account.journal'].create({ + 'name': 'Bank Journal - Test', + 'code': 'AJ-BANK', + 'type': 'bank', + 'company_id': cls.env.user.company_id.id, + }) @classmethod def setUpUsers(cls): @@ -586,10 +600,24 @@ class AccountTestNoChartCommonMultiCompany(AccountTestNoChartCommon): class AccountTestInvoicingCommon(SavepointCase): @classmethod - def setUpClass(cls): + def copy_account(cls, account): + suffix_nb = 1 + while True: + new_code = '%s (%s)' % (account.code, suffix_nb) + if account.search_count([('company_id', '=', account.company_id.id), ('code', '=', new_code)]): + suffix_nb += 1 + else: + return account.copy(default={'code': new_code}) + + @classmethod + def setUpClass(cls, chart_template_ref=None): super(AccountTestInvoicingCommon, cls).setUpClass() - chart_template = cls.env.user.company_id.chart_template_id + chart_template = None + if chart_template_ref: + chart_template = cls.env.ref(chart_template_ref) + if not chart_template: + chart_template = cls.env.user.company_id.chart_template_id if not chart_template: chart_template = cls.env.ref('l10n_generic_coa.configurable_chart_template', raise_if_not_found=False) if not chart_template: @@ -634,8 +662,8 @@ class AccountTestInvoicingCommon(SavepointCase): 'uom_id': cls.env.ref('uom.product_uom_dozen').id, 'lst_price': 200.0, 'standard_price': 160.0, - 'property_account_income_id': cls.company_data['default_account_revenue'].copy().id, - 'property_account_expense_id': cls.company_data['default_account_expense'].copy().id, + 'property_account_income_id': cls.copy_account(cls.company_data['default_account_revenue']).id, + 'property_account_expense_id': cls.copy_account(cls.company_data['default_account_expense']).id, 'taxes_id': [(6, 0, (cls.tax_sale_a + cls.tax_sale_b).ids)], 'supplier_taxes_id': [(6, 0, (cls.tax_purchase_a + cls.tax_purchase_b).ids)], }) @@ -793,29 +821,30 @@ class AccountTestInvoicingCommon(SavepointCase): } @classmethod - def setup_multi_currency_data(cls): - gold_currency = cls.env['res.currency'].create({ + def setup_multi_currency_data(cls, default_values={}, rate2016=3.0, rate2017=2.0): + foreign_currency = cls.env['res.currency'].create({ 'name': 'Gold Coin', 'symbol': '☺', 'rounding': 0.001, 'position': 'after', 'currency_unit_label': 'Gold', 'currency_subunit_label': 'Silver', + **default_values, }) rate1 = cls.env['res.currency.rate'].create({ 'name': '2016-01-01', - 'rate': 3.0, - 'currency_id': gold_currency.id, + 'rate': rate2016, + 'currency_id': foreign_currency.id, 'company_id': cls.env.company.id, }) rate2 = cls.env['res.currency.rate'].create({ 'name': '2017-01-01', - 'rate': 2.0, - 'currency_id': gold_currency.id, + 'rate': rate2017, + 'currency_id': foreign_currency.id, 'company_id': cls.env.company.id, }) return { - 'currency': gold_currency, + 'currency': foreign_currency, 'rates': rate1 + rate2, } @@ -931,9 +960,11 @@ class TestAccountReconciliationCommon(AccountTestCommon): super(TestAccountReconciliationCommon, cls).setUpClass() cls.company = cls.env['res.company'].create({ 'name': 'A test company', - 'currency_id': cls.env.ref('base.EUR').id + 'currency_id': cls.env.ref('base.EUR').id, }) + cls.env.user.company_id = cls.company + cls.env.user.groups_id |= cls.env.ref('account.group_account_user') # Generate minimal data for my new company cls.create_accounting_minimal_data() @@ -1116,41 +1147,36 @@ class TestAccountReconciliationCommon(AccountTestCommon): auto_validate=True ) - def make_payment(self, invoice_record, bank_journal, amount=0.0, amount_currency=0.0, currency_id=None): + def make_payment(self, invoice_record, bank_journal, amount=0.0, amount_currency=0.0, currency_id=None, reconcile_param=[]): bank_stmt = self.acc_bank_stmt_model.create({ 'journal_id': bank_journal.id, 'date': time.strftime('%Y') + '-07-15', - 'name': 'payment' + invoice_record.name - }) - - bank_stmt_line = self.acc_bank_stmt_line_model.create({'name': 'payment', - 'statement_id': bank_stmt.id, - 'partner_id': self.partner_agrolait_id, - 'amount': amount, - 'amount_currency': amount_currency, - 'currency_id': currency_id, - 'date': time.strftime('%Y') + '-07-15', - }) - line_id = invoice_record.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable')) - amount_in_widget = currency_id and amount_currency or amount - bank_stmt_line.process_reconciliation(counterpart_aml_dicts=[{ - 'move_line': line_id, - 'debit': amount_in_widget < 0 and -amount_in_widget or 0.0, - 'credit': amount_in_widget > 0 and amount_in_widget or 0.0, - 'name': line_id.name, - }]) + 'name': 'payment' + invoice_record.name, + 'line_ids': [(0, 0, { + 'payment_ref': 'payment', + 'partner_id': self.partner_agrolait_id, + 'amount': amount, + 'amount_currency': amount_currency, + 'foreign_currency_id': currency_id, + })], + }) + bank_stmt.button_post() + + bank_stmt.line_ids[0].reconcile(reconcile_param) return bank_stmt def make_customer_and_supplier_flows(self, invoice_currency_id, invoice_amount, bank_journal, amount, amount_currency, transaction_currency_id): #we create an invoice in given invoice_currency invoice_record = self.create_invoice(type='out_invoice', invoice_amount=invoice_amount, currency_id=invoice_currency_id) #we encode a payment on it, on the given bank_journal with amount, amount_currency and transaction_currency given - bank_stmt = self.make_payment(invoice_record, bank_journal, amount=amount, amount_currency=amount_currency, currency_id=transaction_currency_id) - customer_move_lines = bank_stmt.move_line_ids + line = invoice_record.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable')) + bank_stmt = self.make_payment(invoice_record, bank_journal, amount=amount, amount_currency=amount_currency, currency_id=transaction_currency_id, reconcile_param=[{'id': line.id}]) + customer_move_lines = bank_stmt.line_ids.line_ids #we create a supplier bill in given invoice_currency invoice_record = self.create_invoice(type='in_invoice', invoice_amount=invoice_amount, currency_id=invoice_currency_id) #we encode a payment on it, on the given bank_journal with amount, amount_currency and transaction_currency given - bank_stmt = self.make_payment(invoice_record, bank_journal, amount=-amount, amount_currency=-amount_currency, currency_id=transaction_currency_id) - supplier_move_lines = bank_stmt.move_line_ids + line = invoice_record.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable')) + bank_stmt = self.make_payment(invoice_record, bank_journal, amount=-amount, amount_currency=-amount_currency, currency_id=transaction_currency_id, reconcile_param=[{'id': line.id}]) + supplier_move_lines = bank_stmt.line_ids.line_ids return customer_move_lines, supplier_move_lines |
