diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/account/tests/test_account_journal.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/account/tests/test_account_journal.py')
| -rw-r--r-- | addons/account/tests/test_account_journal.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/addons/account/tests/test_account_journal.py b/addons/account/tests/test_account_journal.py new file mode 100644 index 00000000..b8644db0 --- /dev/null +++ b/addons/account/tests/test_account_journal.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.tests import tagged +from odoo.exceptions import UserError, ValidationError + + +@tagged('post_install', '-at_install') +class TestAccountJournal(AccountTestInvoicingCommon): + + def test_constraint_currency_consistency_with_accounts(self): + ''' The accounts linked to a bank/cash journal must share the same foreign currency + if specified. + ''' + journal_bank = self.company_data['default_journal_bank'] + journal_bank.currency_id = self.currency_data['currency'] + + # Try to set a different currency on the 'debit' account. + with self.assertRaises(ValidationError), self.cr.savepoint(): + journal_bank.default_account_id.currency_id = self.company_data['currency'] + + def test_changing_journal_company(self): + ''' Ensure you can't change the company of an account.journal if there are some journal entries ''' + + self.env['account.move'].create({ + 'move_type': 'entry', + 'date': '2019-01-01', + 'journal_id': self.company_data['default_journal_sale'].id, + }) + + with self.assertRaises(UserError), self.cr.savepoint(): + self.company_data['default_journal_sale'].company_id = self.company_data_2['company'] + + def test_account_control_create_journal_entry(self): + move_vals = { + 'line_ids': [ + (0, 0, { + 'name': 'debit', + 'account_id': self.company_data['default_account_revenue'].id, + 'debit': 100.0, + 'credit': 0.0, + }), + (0, 0, { + 'name': 'credit', + 'account_id': self.company_data['default_account_expense'].id, + 'debit': 0.0, + 'credit': 100.0, + }), + ], + } + + # Should fail because 'default_account_expense' is not allowed. + self.company_data['default_journal_misc'].account_control_ids |= self.company_data['default_account_revenue'] + with self.assertRaises(UserError), self.cr.savepoint(): + self.env['account.move'].create(move_vals) + + # Should be allowed because both accounts are accepted. + self.company_data['default_journal_misc'].account_control_ids |= self.company_data['default_account_expense'] + self.env['account.move'].create(move_vals) + + def test_account_control_existing_journal_entry(self): + self.env['account.move'].create({ + 'line_ids': [ + (0, 0, { + 'name': 'debit', + 'account_id': self.company_data['default_account_revenue'].id, + 'debit': 100.0, + 'credit': 0.0, + }), + (0, 0, { + 'name': 'credit', + 'account_id': self.company_data['default_account_expense'].id, + 'debit': 0.0, + 'credit': 100.0, + }), + ], + }) + + # There is already an other line using the 'default_account_expense' account. + with self.assertRaises(ValidationError), self.cr.savepoint(): + self.company_data['default_journal_misc'].account_control_ids |= self.company_data['default_account_revenue'] + + # Assigning both should be allowed + self.company_data['default_journal_misc'].account_control_ids = \ + self.company_data['default_account_revenue'] + self.company_data['default_account_expense'] |
