diff --git a/addons/account/tests/test_account_fiscal_year.py b/addons/account/tests/test_account_fiscal_year.py index 85785473ee2..7fe5e6a966e 100644 --- a/addons/account/tests/test_account_fiscal_year.py +++ b/addons/account/tests/test_account_fiscal_year.py @@ -72,8 +72,15 @@ class TestFiscalPosition(AccountingTestCase): self.check_compute_fiscal_year( company, - '2016-03-01', '2016-02-29', + '2015-03-01', + '2016-02-29', + ) + + self.check_compute_fiscal_year( + company, + '2016-03-01', + '2016-03-01', '2017-02-28', ) diff --git a/odoo/tools/date_utils.py b/odoo/tools/date_utils.py index 55220ced033..26bfdabd835 100644 --- a/odoo/tools/date_utils.py +++ b/odoo/tools/date_utils.py @@ -55,8 +55,19 @@ def get_fiscal_year(date, day=31, month=12): ''' max_day = calendar.monthrange(date.year, month)[1] date_to = type(date)(date.year, month, min(day, max_day)) + + # Force at 29 February instead of 28 in case of leap year. + if date_to.month == 2 and date_to.day == 28 and max_day == 29: + date_to = type(date)(date.year, 2, 29) + if date <= date_to: date_from = date_to - relativedelta(years=1) + max_day = calendar.monthrange(date_from.year, date_from.month)[1] + + # Force at 29 February instead of 28 in case of leap year. + if date_from.month == 2 and date_from.day == 28 and max_day == 29: + date_from = type(date)(date_from.year, 2, 29) + date_from += relativedelta(days=1) else: date_from = date_to + relativedelta(days=1)