Skip to content

Commit

Permalink
[FIX] account: leap year
Browse files Browse the repository at this point in the history
If the end of the accounting period is set to the 28-29th of February,
crashes may occur in date computation.

opw-752939
  • Loading branch information
nim-odoo committed Jul 19, 2017
1 parent 9494161 commit 41433de
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions addons/account/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ def compute_fiscalyear_dates(self, date):
if (date.month < last_month or (date.month == last_month and date.day <= last_day)):
date = date.replace(month=last_month, day=last_day)
else:
date = date.replace(month=last_month, day=last_day, year=date.year + 1)
if last_month == 2 and last_day == 29 and (date.year + 1) % 4 != 0:

This comment has been minimized.

Copy link
@yvaucher

yvaucher Jul 20, 2017

Contributor

@nim-odoo Please use calendar lib calendar.isleap() for leap year. The rule is a bit more complicated.

https://en.wikipedia.org/wiki/Leap_year

date = date.replace(month=last_month, day=28, year=date.year + 1)
else:
date = date.replace(month=last_month, day=last_day, year=date.year + 1)
date_to = date
date_from = date + timedelta(days=1)
date_from = date_from.replace(year=date_from.year - 1)
if date_from.month == 2 and date_from.day == 29:
date_from = date_from.replace(day=28, year=date_from.year - 1)
else:
date_from = date_from.replace(year=date_from.year - 1)
return {'date_from': date_from, 'date_to': date_to}

def get_new_account_code(self, current_code, old_prefix, new_prefix, digits):
Expand Down

0 comments on commit 41433de

Please sign in to comment.