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 | |
| 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')
| -rw-r--r-- | addons/account/models/company.py | 33 | ||||
| -rw-r--r-- | addons/account/tests/test_account_move_entry.py | 4 |
2 files changed, 26 insertions, 11 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""" diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index b0e6eb642a5..1d87a9b935e 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -3,7 +3,7 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon from odoo.tests import tagged, new_test_user from odoo.tests.common import Form from odoo import fields -from odoo.exceptions import ValidationError, UserError +from odoo.exceptions import ValidationError, UserError, RedirectWarning from dateutil.relativedelta import relativedelta from functools import reduce @@ -156,7 +156,7 @@ class TestAccountMove(AccountTestInvoicingCommon): statement.button_post() # You can't lock the fiscal year if there is some unreconciled statement. - with self.assertRaises(ValidationError), self.cr.savepoint(): + with self.assertRaises(RedirectWarning), self.cr.savepoint(): self.test_move.company_id.fiscalyear_lock_date = fields.Date.from_string('2017-01-01') def test_misc_tax_lock_date_1(self): |
