summaryrefslogtreecommitdiff
path: root/addons/account/tests/test_account_analytic.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account/tests/test_account_analytic.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account/tests/test_account_analytic.py')
-rw-r--r--addons/account/tests/test_account_analytic.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/addons/account/tests/test_account_analytic.py b/addons/account/tests/test_account_analytic.py
new file mode 100644
index 00000000..48ab4258
--- /dev/null
+++ b/addons/account/tests/test_account_analytic.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+from odoo.addons.account.tests.common import AccountTestInvoicingCommon
+from odoo.tests import tagged
+from odoo.exceptions import UserError
+
+
+@tagged('post_install', '-at_install')
+class TestAccountAnalyticAccount(AccountTestInvoicingCommon):
+
+ @classmethod
+ def setUpClass(cls, chart_template_ref=None):
+ super().setUpClass(chart_template_ref=chart_template_ref)
+
+ cls.env.user.write({
+ 'groups_id': [
+ (4, cls.env.ref('analytic.group_analytic_accounting').id),
+ (4, cls.env.ref('analytic.group_analytic_tags').id),
+ ],
+ })
+
+ # By default, tests are run with the current user set on the first company.
+ cls.env.user.company_id = cls.company_data['company']
+
+ cls.test_analytic_account = cls.env['account.analytic.account'].create({'name': 'test_analytic_account'})
+ cls.test_analytic_tag = cls.env['account.analytic.tag'].create({'name': 'test_analytic_tag'})
+
+ def test_changing_analytic_company(self):
+ ''' Ensure you can't change the company of an account.analytic.account if there are some journal entries '''
+
+ self.env['account.move'].create({
+ 'move_type': 'entry',
+ 'date': '2019-01-01',
+ 'line_ids': [
+ (0, 0, {
+ 'name': 'line_debit',
+ 'account_id': self.company_data['default_account_revenue'].id,
+ 'analytic_account_id': self.test_analytic_account.id,
+ 'analytic_tag_ids': [(6, 0, self.test_analytic_tag.ids)],
+ }),
+ (0, 0, {
+ 'name': 'line_credit',
+ 'account_id': self.company_data['default_account_revenue'].id,
+ }),
+ ],
+ })
+
+ # Set a different company on the analytic account.
+ with self.assertRaises(UserError), self.cr.savepoint():
+ self.test_analytic_account.company_id = self.company_data_2['company']
+
+ # Making the analytic account not company dependent is allowed.
+ self.test_analytic_account.company_id = False
+
+ # Set a different company on the analytic tag.
+ with self.assertRaises(UserError), self.cr.savepoint():
+ self.test_analytic_tag.company_id = self.company_data_2['company']
+
+ # Making the analytic tag not company dependent is allowed.
+ self.test_analytic_tag.company_id = False