diff --git a/addons/l10n_generic_coa/tests/__init__.py b/addons/l10n_generic_coa/tests/__init__.py index 00c4868b8a2..f08703304df 100644 --- a/addons/l10n_generic_coa/tests/__init__.py +++ b/addons/l10n_generic_coa/tests/__init__.py @@ -1,5 +1,2 @@ # -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import test_account_invoice_state -from . import test_account_bank_statement +from . import test_base_objects diff --git a/addons/l10n_generic_coa/tests/test_account_bank_statement.py b/addons/l10n_generic_coa/tests/test_account_bank_statement.py deleted file mode 100644 index 1d12a23031f..00000000000 --- a/addons/l10n_generic_coa/tests/test_account_bank_statement.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests import common -import time -from odoo import tools -from odoo.modules.module import get_resource_path - - -class TestAccountBankStatement(common.TransactionCase): - - 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') diff --git a/addons/l10n_generic_coa/tests/test_account_invoice_state.py b/addons/l10n_generic_coa/tests/test_account_invoice_state.py deleted file mode 100644 index 563b5cdf19b..00000000000 --- a/addons/l10n_generic_coa/tests/test_account_invoice_state.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests.common import TransactionCase - - -class TestAccountInvoiceState(TransactionCase): - - def test_00_account_invoice_state_flow(self): - """Test Account Invoice State""" - - # Create an invoice and confirm it with this wizard - default_get_vals = self.env['account.invoice'].default_get(list(self.env['account.invoice'].fields_get())) - account_invoice = self.env['account.invoice'].new(default_get_vals) - account_invoice._onchange_journal_id() - account_invoice.partner_id = self.ref('base.res_partner_12') - account_invoice._onchange_partner_id() - account_invoice.invoice_line_ids = [(0, 0, { - 'name': 'Computer SC234', - 'price_unit': 450.0, - 'quantity': 1.0, - 'product_id': self.ref('product.product_product_3'), - 'uom_id': self.ref('product.product_uom_unit'), - 'invoice_id': account_invoice, # This value is required for '_onchange_product_id' to work correctly - })] - account_invoice.invoice_line_ids._onchange_product_id() - account_invoice._onchange_invoice_line_ids() - vals = account_invoice._convert_to_write(account_invoice._cache) - account_invoice = self.env['account.invoice'].create(vals) - - # Check account invoice state - self.assertEqual(account_invoice.state, 'draft', 'Account: Invoice state should be draft') - - # Clicked on "Confirm Invoices" Button - self.env['account.invoice.confirm'].with_context({ - "lang": 'en_US', - "tz": False, - "active_model": "account.invoice", - "active_ids": [account_invoice.id], - "type": "out_invoice", - "active_id": account_invoice.id - }).invoice_confirm() - - # Check that customer invoice state is "Open" - self.assertEqual(account_invoice.state, 'open', 'Account: invoice state should be open') - - # Check the journal associated and put this journal as not - moves_line = self.env['account.move.line'].search([ - ('invoice_id', '=', account_invoice.id) - ]) - # Check you have multiple move lines - self.assertEqual(len(moves_line), 2, 'You should have multiple move lines') - - moves_line[0].journal_id.write({'update_posted': True}) - - # I cancelled this open invoice using the button on invoice - account_invoice.action_invoice_cancel() - - # Check that customer invoice is in the cancel state - self.assertEqual(account_invoice.state, 'cancel', 'Account: invoice state should be cancelled') diff --git a/addons/l10n_generic_coa/tests/test_base_objects.py b/addons/l10n_generic_coa/tests/test_base_objects.py new file mode 100644 index 00000000000..c43eb111843 --- /dev/null +++ b/addons/l10n_generic_coa/tests/test_base_objects.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +import time + +from odoo import fields +from odoo.tests.common import TransactionCase, Form + +class TestAccountBankStatement(TransactionCase): + """ + In order to test Bank Statement feature of account I create a bank + statement line and confirm it and check it's move created + """ + def test_basic(self): + env = self.env(context=dict(self.env.context, journal_type='bank')) + + # select the period and journal for the bank statement + journal = env['account.bank.statement'].with_context( + date=time.strftime("%Y/%m/%d"), # ??? + )._default_journal() + self.assertTrue(journal, 'Journal has not been selected') + + f = Form(env['account.bank.statement']) + # necessary as there may be existing bank statements with a non-zero + # closing balance which will be used to initialise this one. + f.balance_start = 0.0 + f.balance_end_real = 0.0 + with f.line_ids.new() as line: + line.name = 'EXT001' + line.amount = 1000 + line.partner_id = env.ref('base.res_partner_4') + + statement_id = f.save() + + # process the bank statement line + account = env['account.account'].create({ + 'name': 'toto', + 'code': 'bidule', + 'user_type_id': env.ref('account.data_account_type_fixed_assets').id + }) + statement_id.line_ids[0].process_reconciliation(new_aml_dicts=[{ + 'credit': 1000, + 'debit': 0, + 'name': 'toto', + 'account_id': account.id, + }]) + + with Form(statement_id) as f: + # modify the bank statement and set the Ending Balance. + f.balance_end_real = 1000.0 + + # confirm the bank statement using Validate button + statement_id.button_confirm_bank() + + self.assertEqual(statement_id.state, 'confirm') + +class TestAccountInvoice(TransactionCase): + def test_state(self): + # In order to test Confirm Draft Invoice wizard I create an invoice + # and confirm it with this wizard + f = Form(self.env['account.invoice']) + f.partner_id = self.env.ref('base.res_partner_12') + with f.invoice_line_ids.new() as l: + l.product_id = self.env.ref('product.product_product_3') + invoice = f.save() + + # I check that Initially customer invoice state is "Draft" + self.assertEqual(invoice.state, 'draft') + + # I called the "Confirm Draft Invoices" wizard + w = Form(self.env['account.invoice.confirm']).save() + # I clicked on Confirm Invoices Button + w.with_context( + active_model='account.invoice', + active_id=invoice.id, + active_ids=invoice.ids, + type='out_invoice', + ).invoice_confirm() + + # I check that customer invoice state is "Open" + self.assertEqual(invoice.state, 'open') + + # I check the journal associated and put this journal as not + moves = self.env['account.move.line'].search([ + ('invoice_id', '=', invoice.id) + ]) + self.assertGreater(len(moves), 0, 'You should have multiple moves') + moves[0].journal_id.write({'update_posted': True}) + + # I cancelled this open invoice using the button on invoice + invoice.action_invoice_cancel() + # I check that customer invoice is in the cancel state + self.assertEqual(invoice.state, 'cancel')