diff --git a/addons/account/models/company.py b/addons/account/models/company.py index b8e85a9c532..25f1c1592b1 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -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