File: test_company_fiscal_year.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (102 lines) | stat: -rw-r--r-- 3,505 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.tests.common import TransactionCase

from datetime import date


class SpreadsheetFiscalYearTest(TransactionCase):
    def test_fiscal_year_reference(self):
        self.env.company.fiscalyear_last_day = 3
        self.env.company.fiscalyear_last_month = "2"

        self.assertEqual(
            self.env["res.company"].get_fiscal_dates(
                [{"company_id": None, "date": "2020-03-05"}]
            ),
            [
                {"start": date(2020, 2, 4), "end": date(2021, 2, 3)},
            ],
        )

    def test_fiscal_year_reference_last_day(self):
        self.env.company.fiscalyear_last_day = 3
        self.env.company.fiscalyear_last_month = "2"

        self.assertEqual(
            self.env["res.company"].get_fiscal_dates(
                [{"company_id": None, "date": "2020-02-03"}]
            ),
            [
                {"start": date(2019, 2, 4), "end": date(2020, 2, 3)},
            ],
        )

    def test_fiscal_year_reference_first_day(self):
        self.env.company.fiscalyear_last_day = 3
        self.env.company.fiscalyear_last_month = "2"

        self.assertEqual(
            self.env["res.company"].get_fiscal_dates(
                [{"company_id": None, "date": "2020-02-04"}]
            ),
            [{"start": date(2020, 2, 4), "end": date(2021, 2, 3)}],
        )

    def test_fiscal_year_with_company_id(self):
        self.env.company.fiscalyear_last_day = 7
        self.env.company.fiscalyear_last_month = "6"
        company = self.env["res.company"].create(
            {
                "name": "test company",
                "fiscalyear_last_day": 3,
                "fiscalyear_last_month": "2",
            }
        )
        self.assertEqual(
            self.env["res.company"].get_fiscal_dates(
                [
                    {"company_id": company.id, "date": "2020-02-04"},
                    {"company_id": None, "date": "2020-02-04"},
                ]
            ),
            [
                {"start": date(2020, 2, 4), "end": date(2021, 2, 3)},
                {"start": date(2019, 6, 8), "end": date(2020, 6, 7)},
            ],
        )

    def test_result_order(self):
        company = self.env["res.company"].create(
            {
                "name": "test company",
                "fiscalyear_last_day": 3,
                "fiscalyear_last_month": "2",
            }
        )
        request1 = {"company_id": company.id, "date": "2020-02-04"}
        request2 = {"company_id": None, "date": "2020-02-04"}
        [o1_request1, o1_request2] = self.env["res.company"].get_fiscal_dates(
            [request1, request2]
        )
        [o2_request2, o2_request1] = self.env["res.company"].get_fiscal_dates(
            [request2, request1]
        )
        self.assertEqual(o1_request1, o2_request1)
        self.assertEqual(o1_request2, o2_request2)

    def test_fiscal_year_with_wrong_company_id(self):
        self.env.company.fiscalyear_last_day = 7
        self.env.company.fiscalyear_last_month = "6"
        self.assertEqual(
            self.env["res.company"].get_fiscal_dates(
                [
                    {"company_id": 999, "date": "2020-02-04"},
                    {"company_id": None, "date": "2020-02-04"},
                ]
            ),
            [
                False,
                {"start": date(2019, 6, 8), "end": date(2020, 6, 7)},
            ],
        )