From 5da551a0d055de6f01dd2c2cd60b240631605626 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 21 Sep 2017 11:05:36 +0200 Subject: [PATCH] [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 --- addons/account/models/company.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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