diff options
| author | Florian Gilbert <flg@odoo.com> | 2020-08-03 09:02:58 +0000 |
|---|---|---|
| committer | Florian Gilbert <flg@odoo.com> | 2020-08-07 06:59:25 +0000 |
| commit | 2720cf570c72edb806ba3401b60be42e0574a075 (patch) | |
| tree | 789b85cbdc9df90bfc35c82c13c55c92129aa0e0 /addons/account/models/company.py | |
| parent | 6a7ac8eee1337049647a020f87b720d9f5cf2539 (diff) | |
[IMP] account: Change Validation error to redirect warning for lock date
Change ValidationError to RedirectWarning, RedirectWarning is usefull to redirect user to
the problem. For the lock date, we can redirect user to unposted entries or unreconciled bank statement lines.
Task ID: 2297407
Diffstat (limited to 'addons/account/models/company.py')
| -rw-r--r-- | addons/account/models/company.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/addons/account/models/company.py b/addons/account/models/company.py index d3e3ce03f30..c8760934807 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -188,21 +188,36 @@ class ResCompany(models.Model): def _validate_fiscalyear_lock(self, values): if values.get('fiscalyear_lock_date'): - nb_draft_entries = self.env['account.move'].search([ + draft_entries = self.env['account.move'].search([ ('company_id', 'in', self.ids), ('state', '=', 'draft'), ('date', '<=', values['fiscalyear_lock_date'])]) - if nb_draft_entries: - raise ValidationError(_('There are still unposted entries in the period you want to lock. You should either post or delete them.')) - - has_unreconciled_statement_lines = self.env['account.bank.statement.line'].search_count([ + if draft_entries: + error_msg = _('There are still unposted entries in the period you want to lock. You should either post or delete them.') + action_error = { + 'view_mode': 'tree', + 'name': 'Unposted Entries', + 'res_model': 'account.move', + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', draft_entries.ids)], + 'search_view_id': [self.env.ref('account.view_account_move_filter').id, 'search'], + 'views': [[self.env.ref('account.view_move_tree').id, 'list'], [self.env.ref('account.view_move_form').id, 'form']], + } + raise RedirectWarning(error_msg, action_error, _('Show unposted entries')) + + unreconciled_statement_lines = self.env['account.bank.statement.line'].search([ ('company_id', 'in', self.ids), ('is_reconciled', '=', False), ]) - if has_unreconciled_statement_lines: - raise ValidationError(_( - "There are still unreconciled bank statement lines in the period you want to lock." - "You should either reconcile or delete them.")) + if unreconciled_statement_lines: + error_msg = _("There are still unreconciled bank statement lines in the period you want to lock." + "You should either reconcile or delete them.") + action_error = { + 'type': 'ir.actions.client', + 'tag': 'bank_statement_reconciliation_view', + 'context': {'statement_line_ids': unreconciled_statement_lines.ids, 'company_ids': self.ids}, + } + raise RedirectWarning(error_msg, action_error, _('Show Unreconciled Bank Statement Line')) def _get_user_fiscal_lock_date(self): """Get the fiscal lock date for this company depending on the user""" |
