summaryrefslogtreecommitdiff
path: root/addons/account/tests/test_account_analytic.py
blob: 48ab4258ffb55a2b2e5a2561f11c45ca5ef09e7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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