From c017f44f4ff6f6e1cfe1210161645fa4931433de Mon Sep 17 00:00:00 2001 From: "Gauthier Wala (gawa)" Date: Mon, 5 Feb 2024 15:28:55 +0100 Subject: [PATCH] [FIX] tools: fiscal year of 30/12 is taken as 31 To reproduce: - Put your fiscal year to the 30th of December (yes it's unlikely) - Create an asset - Compute depreciations => they are created for the 31th of December It comes from the `get_fiscal_year` in `date_utils` which considers it as the case of the 28th of February opw-3704466 closes odoo/odoo#153528 X-original-commit: cd0bb178441790e7e33c0d1c01b7ade82d4ab8c0 Signed-off-by: Florian Gilbert (flg) --- odoo/addons/base/tests/__init__.py | 1 + odoo/addons/base/tests/test_date_utils.py | 26 +++++++++++++++++++++++ odoo/tools/date_utils.py | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 odoo/addons/base/tests/test_date_utils.py diff --git a/odoo/addons/base/tests/__init__.py b/odoo/addons/base/tests/__init__.py index 515b927915a..73db3d3dd27 100644 --- a/odoo/addons/base/tests/__init__.py +++ b/odoo/addons/base/tests/__init__.py @@ -7,6 +7,7 @@ from . import test_barcode from . import test_base from . import test_basecase from . import test_cache +from . import test_date_utils from . import test_deprecation from . import test_db_cursor from . import test_display_name diff --git a/odoo/addons/base/tests/test_date_utils.py b/odoo/addons/base/tests/test_date_utils.py new file mode 100644 index 00000000000..f4047c1f847 --- /dev/null +++ b/odoo/addons/base/tests/test_date_utils.py @@ -0,0 +1,26 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from datetime import date + +from odoo.tests import BaseCase +from odoo.tools.date_utils import get_fiscal_year + + +class TestDateUtils(BaseCase): + + def test_fiscal_year(self): + self.assertEqual(get_fiscal_year(date(2024, 12, 31)), (date(2024, 1, 1), date(2024, 12, 31))) + self.assertEqual(get_fiscal_year(date(2024, 12, 31), 30, 11), (date(2024, 12, 1), date(2025, 11, 30))) + self.assertEqual(get_fiscal_year(date(2024, 10, 31), 30, 11), (date(2023, 12, 1), date(2024, 11, 30))) + self.assertEqual(get_fiscal_year(date(2024, 10, 31), 30, 12), (date(2023, 12, 31), date(2024, 12, 30))) + + self.assertEqual(get_fiscal_year(date(2024, 10, 31), month=11), (date(2023, 12, 1), date(2024, 11, 30))) + self.assertEqual(get_fiscal_year(date(2024, 2, 29)), (date(2024, 1, 1), date(2024, 12, 31))) + + self.assertEqual(get_fiscal_year(date(2024, 12, 31), 29, 2), (date(2024, 3, 1), date(2025, 2, 28))) + self.assertEqual(get_fiscal_year(date(2024, 12, 31), 28, 2), (date(2024, 3, 1), date(2025, 2, 28))) + self.assertEqual(get_fiscal_year(date(2023, 12, 31), 28, 2), (date(2023, 3, 1), date(2024, 2, 29))) + self.assertEqual(get_fiscal_year(date(2023, 12, 31), 29, 2), (date(2023, 3, 1), date(2024, 2, 29))) + + self.assertEqual(get_fiscal_year(date(2024, 2, 29), 28, 2), (date(2023, 3, 1), date(2024, 2, 29))) + self.assertEqual(get_fiscal_year(date(2023, 2, 28), 28, 2), (date(2022, 3, 1), date(2023, 2, 28))) + self.assertEqual(get_fiscal_year(date(2023, 2, 28), 29, 2), (date(2022, 3, 1), date(2023, 2, 28))) diff --git a/odoo/tools/date_utils.py b/odoo/tools/date_utils.py index 05ab361cb57..fba7910bed3 100644 --- a/odoo/tools/date_utils.py +++ b/odoo/tools/date_utils.py @@ -65,7 +65,7 @@ def get_fiscal_year(date, day=31, month=12): def fix_day(year, month, day): max_day = calendar.monthrange(year, month)[1] - if (month == 2 and day in (28, max_day)) or (month != 2 and day in (30, max_day)): + if month == 2 and day in (28, max_day): return max_day return min(day, max_day)