2017-07-06 09:40:15 +02:00
|
|
|
# Copyright 2017 ACSONE SA/NV
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2020-11-17 00:00:36 +01:00
|
|
|
from psycopg2 import IntegrityError
|
|
|
|
|
2017-07-06 09:40:15 +02:00
|
|
|
from odoo.exceptions import UserError
|
|
|
|
from odoo.fields import Date
|
|
|
|
from odoo.tests.common import TransactionCase
|
2018-03-17 06:18:58 +01:00
|
|
|
from odoo.tools import mute_logger
|
2017-07-06 09:40:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAccountFiscalMonth(TransactionCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestAccountFiscalMonth, self).setUp()
|
2020-11-17 00:00:36 +01:00
|
|
|
self.DateRangeObj = self.env["date.range"]
|
|
|
|
self.DateRangeType = self.env["date.range.type"]
|
2017-07-06 09:40:15 +02:00
|
|
|
|
2020-11-17 00:00:36 +01:00
|
|
|
self.company = self.env.ref("base.main_company")
|
2018-03-17 06:18:58 +01:00
|
|
|
|
|
|
|
self.date_range_type = self.DateRangeType.create(
|
2020-11-17 00:00:36 +01:00
|
|
|
{"name": "Other Type", "allow_overlap": False}
|
|
|
|
)
|
2017-07-06 09:40:15 +02:00
|
|
|
self.date_range_type_month = self.env.ref(
|
2020-11-17 00:00:36 +01:00
|
|
|
"account_fiscal_month.date_range_fiscal_month"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.date_range_1 = self.DateRangeObj.create(
|
|
|
|
{
|
|
|
|
"name": "Other",
|
|
|
|
"date_start": "2017-01-01",
|
|
|
|
"date_end": "2017-01-31",
|
|
|
|
"type_id": self.date_range_type.id,
|
|
|
|
"company_id": self.company.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.date_range_january_2017 = self.DateRangeObj.create(
|
|
|
|
{
|
|
|
|
"name": "January 2017",
|
|
|
|
"date_start": "2017-01-01",
|
|
|
|
"date_end": "2017-01-31",
|
|
|
|
"type_id": self.date_range_type_month.id,
|
|
|
|
"company_id": self.company.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
self.date_range_january_no_comp_2017 = self.DateRangeObj.create(
|
|
|
|
{
|
|
|
|
"name": "January 2017",
|
|
|
|
"date_start": "2017-01-01",
|
|
|
|
"date_end": "2017-01-31",
|
|
|
|
"type_id": self.date_range_type_month.id,
|
|
|
|
"company_id": False,
|
|
|
|
}
|
|
|
|
)
|
2017-07-06 09:40:15 +02:00
|
|
|
|
2018-03-17 06:18:58 +01:00
|
|
|
def test_00_delete_type(self):
|
2020-11-17 00:00:36 +01:00
|
|
|
with self.assertRaises(IntegrityError), mute_logger("odoo.sql_db"):
|
2018-03-17 06:18:58 +01:00
|
|
|
self.date_range_type.unlink()
|
|
|
|
|
2017-07-06 09:40:15 +02:00
|
|
|
def test_01_delete_type_fiscal_month(self):
|
|
|
|
with self.assertRaises(UserError):
|
|
|
|
self.date_range_type_month.unlink()
|
|
|
|
|
|
|
|
def test_02_search_date_range(self):
|
2020-11-17 00:00:36 +01:00
|
|
|
january_2017_1st = Date.from_string("2017-01-01")
|
2017-07-06 09:40:15 +02:00
|
|
|
date_ranges = self.company.find_daterange_fm(january_2017_1st)
|
|
|
|
|
2021-09-27 17:26:48 +02:00
|
|
|
self.assertEqual(len(date_ranges), 1)
|
|
|
|
self.assertEqual(date_ranges[0], self.date_range_january_2017)
|