[FIX] account: fiscal year end dates in wizard

- From Accounting dashboard > Configuration panel > Configure fiscal year
- Set opening date: 01/07/2018
- Set fiscal year end: June 30
- Click Apply button

An error is raised: 'Invalid fiscal year last day'.

This is because the 3 fields are linked by the constraint
`_check_fiscalyear_last_day`. However, non-stored writeable related
fields are evaluated one at a time, meaning that the constraint is
evaluated one value at a time.

We do a fancy workaround to write the 3 values at once on the company,
hence evaluating the constraint for the 3 fields once.

opw-2024927

closes odoo/odoo#34275

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-06-20 10:51:56 +00:00
parent 53b6ab9f05
commit 988018a5ba
+17
View File
@@ -23,6 +23,23 @@ class FinancialYearOpeningWizard(models.TransientModel):
for record in self:
record.opening_move_posted = record.company_id.opening_move_posted()
@api.multi
def write(self, vals):
# Amazing workaround: non-stored related fields on company are a BAD idea since the 3 fields
# must follow the constraint '_check_fiscalyear_last_day'. The thing is, in case of related
# fields, the inverse write is done one value at a time, and thus the constraint is verified
# one value at a time... so it is likely to fail.
for wiz in self:
wiz.company_id.write({
'account_opening_date': vals.get('opening_date') or wiz.company_id.account_opening_date,
'fiscalyear_last_day': vals.get('fiscalyear_last_day') or wiz.company_id.fiscalyear_last_day,
'fiscalyear_last_month': vals.get('fiscalyear_last_month') or wiz.company_id.fiscalyear_last_month,
})
vals.pop('opening_date', None)
vals.pop('fiscalyear_last_day', None)
vals.pop('fiscalyear_last_month', None)
return super().write(vals)
@api.multi
def action_save_onboarding_fiscal_year(self):
self.env.user.company_id.set_onboarding_step_done('account_setup_fy_data_state')