diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2019-06-20 10:47:24 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-06-20 10:51:56 +0000 |
| commit | 988018a5baa1a10ee44eaeff3065bd8ce4859877 (patch) | |
| tree | 5d917468e7b8f2636d713453757f339713ec1530 /addons | |
| parent | 53b6ab9f05472de35326bfc79e39219a263d3885 (diff) | |
[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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/account/wizard/setup_wizards.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/addons/account/wizard/setup_wizards.py b/addons/account/wizard/setup_wizards.py index 096604b13d7..bd1ebbfb2ae 100644 --- a/addons/account/wizard/setup_wizards.py +++ b/addons/account/wizard/setup_wizards.py @@ -24,6 +24,23 @@ class FinancialYearOpeningWizard(models.TransientModel): 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') |
