summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2019-04-03 08:52:36 +0000
committerNicolas Martinelli <nim@odoo.com>2019-04-03 09:29:57 +0000
commit1e558bc79a40aeee3fc9c4cd1fd30e8b100db112 (patch)
treef92506a199a8ffc5763dd7f21e0e44cc598b7129 /odoo
parent2c702108b815014c9bbb0c910280a4aeea15abc7 (diff)
[FIX] tools: February 28th
- Set your fiscal year end date to 28th February - Run the P&L a year before a leap year, e.g. anytime between March 1st and December 31st 2019. - Select 'Last Financial Year' The dates are set from 2019-03-01 to 2019-02-28. There are actually 2 bugs. The one solved here is the following inconsistency: ``` current_date = type(date)(2019, 4, 3) date_utils.get_fiscal_year(current_date, day=28, month=2) 'date_from': datetime.date(2019, 3, 1), 'date_to': datetime.date(2020, 2, 28) current_date = type(date)(2020, 2, 28) date_utils.get_fiscal_year(current_date, day=28, month=2) {'date_from': datetime.date(2019, 3, 1), 'date_to': datetime.date(2020, 2, 29)} ``` Both should return `'date_to': datetime.date(2020, 2, 29)`. This implies that the period is recognized as `custom`, which is affected by the bug solved in PR https://github.com/odoo/enterprise/pull/4006 opw-1949628 closes odoo/odoo#32366 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/tools/date_utils.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/odoo/tools/date_utils.py b/odoo/tools/date_utils.py
index 26bfdabd835..702913ff04e 100644
--- a/odoo/tools/date_utils.py
+++ b/odoo/tools/date_utils.py
@@ -73,6 +73,10 @@ def get_fiscal_year(date, day=31, month=12):
date_from = date_to + relativedelta(days=1)
max_day = calendar.monthrange(date_to.year + 1, date_to.month)[1]
date_to = type(date)(date.year + 1, 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 += relativedelta(days=1)
return date_from, date_to