[FIX] account: fiscal day should fall within month boundaries
Before this commit, it was possible to set an illegal date such as november 31st as the fiscal date, messing with all the reports Now, a new constraint is implemented at save time to ensure the date is correct closes #19612
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta, datetime
|
||||
import calendar
|
||||
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
@@ -61,6 +62,14 @@ Best Regards,''')
|
||||
account_setup_coa_done = fields.Boolean(string='Chart of Account Checked', help="Technical field holding the status of the chart of account setup step.")
|
||||
account_setup_bar_closed = fields.Boolean(string='Setup Bar Closed', help="Technical field set to True when setup bar has been closed by the user.")
|
||||
|
||||
@api.constrains('fiscalyear_last_month', 'fiscalyear_last_day')
|
||||
def _fiscalyear_last_day_in_month(self):
|
||||
current_year = datetime.now().year
|
||||
for company in self:
|
||||
if company.fiscalyear_last_day > calendar.monthrange(current_year, company.fiscalyear_last_month)[1]:
|
||||
raise ValidationError(_('The day %s does not exist for the month %s when setting the fiscal year on company %s')
|
||||
% (company.fiscalyear_last_day, company.fiscalyear_last_month, company.name))
|
||||
|
||||
@api.multi
|
||||
def compute_fiscalyear_dates(self, date):
|
||||
""" Computes the start and end dates of the fiscalyear where the given 'date' belongs to
|
||||
|
||||
Reference in New Issue
Block a user