[FIX] account: modify the way the fiscal year is constained.

Commit a7ac2cf9fbb57242c1f528c4d6604af0e1509dae attempted at introducing a python constraint to make the fiscal day fall within the month boundaries (eg. not to be able to set Feb 30th)
The constrain appeared to fail depending on the order of its dependencies' evaluation.

After this present commit, we force the out of bounds given date to be the last day of the month
This commit is contained in:
Lucas Perais (lpe)
2017-09-26 09:30:15 +02:00
parent 0510970d12
commit 9edab0dbb4
2 changed files with 22 additions and 8 deletions
+7 -6
View File
@@ -62,13 +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):
@api.model
def _verify_fiscalyear_last_day(self, company_id, last_day, last_month):
company = self.browse(company_id)
last_day = last_day or company.fiscalyear_last_day
last_month = last_month or company.fiscalyear_last_month
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))
last_day_of_month = calendar.monthrange(current_year, last_month)[1]
return last_day > last_day_of_month and last_day_of_month or last_day
@api.multi
def compute_fiscalyear_dates(self, date):
+15 -2
View File
@@ -10,10 +10,12 @@ class FinancialYearOpeningWizard(models.TransientModel):
company_id = fields.Many2one(comodel_name='res.company', required=True)
opening_move_posted = fields.Boolean(string='Opening Move Posted', compute='_compute_opening_move_posted')
opening_date = fields.Date(string='Opening Date', required=True, related='company_id.account_opening_date', help="Date from which the accounting is managed in Odoo. It is the date of the opening entry.")
fiscalyear_last_day = fields.Integer(related="company_id.fiscalyear_last_day", required=True)
fiscalyear_last_day = fields.Integer(related="company_id.fiscalyear_last_day", required=True,
help="The last day of the month will be taken if the chosen day doesn't exist.")
fiscalyear_last_month = fields.Selection(selection=[(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')],
related="company_id.fiscalyear_last_month",
required=True)
required=True,
help="The last day of the month will be taken if the chosen day doesn't exist.")
account_setup_fy_data_done = fields.Boolean(string='Financial year setup marked as done', compute="_compute_setup_marked_done")
@api.depends('company_id.account_setup_fy_data_done')
@@ -34,6 +36,17 @@ class FinancialYearOpeningWizard(models.TransientModel):
""" Forces fiscal year setup state to 'undone'."""
self.company_id.account_setup_fy_data_done = False
@api.multi
def write(self, vals):
if 'fiscalyear_last_day' in vals or 'fiscalyear_last_month' in vals:
for wizard in self:
company = wizard.company_id
vals['fiscalyear_last_day'] = company._verify_fiscalyear_last_day(
company.id,
vals.get('fiscalyear_last_day'),
vals.get('fiscalyear_last_month'))
return super(FinancialYearOpeningWizard, self).write(vals)
class OpeningAccountMoveWizard(models.TransientModel):
_name = 'account.opening'