[IMP] account: check non reconcilable accounts for configured journals

Beforehand, users could configure an account as non reconcilable
even when it was configured as a payment credit or debit account
in a journal. This prevented journal items to be reconciled

Now, when a user tries to set an account as non reconcilable,
we check if there is no journal with a payment credit or debit account
set to this particular account. If there is at least one journal,
then we display an error message stating the journals names and ids
that the user would have to modify before changing the account
configuration.

closes odoo/odoo#69317

X-original-commit: 87c207f3a408abb93d9b8378ef4aa1744935d86d
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: Julien CHEVREAU <Julien-CHEVREAU@users.noreply.github.com>
This commit is contained in:
Julien CHEVREAU (JCU)
2021-04-15 12:40:17 +00:00
parent b2a3471293
commit d5270c1c8a
4 changed files with 45 additions and 1 deletions
+8
View File
@@ -11584,6 +11584,14 @@ msgstr ""
msgid "The account %s (%s) is deprecated."
msgstr ""
#. module: account
#: code:addons/account/models/account_account.py:0
#, python-format
msgid ""
"This account is configured in %(journal_names)s journal(s) (ids %(journal_ids)s) as payment debit or credit account. "
"This means that this account's type should be reconcilable."
msgstr ""
#. module: account
#: code:addons/account/models/account_account.py:0
#, python-format
+26
View File
@@ -188,6 +188,32 @@ class AccountAccount(models.Model):
if self._cr.fetchone():
raise ValidationError(_("The account is already in use in a 'sale' or 'purchase' journal. This means that the account's type couldn't be 'receivable' or 'payable'."))
@api.constrains('reconcile')
def _check_used_as_journal_default_debit_credit_account(self):
accounts = self.filtered(lambda a: not a.reconcile)
if not accounts:
return
self.flush(['reconcile'])
self._cr.execute('''
SELECT journal.id
FROM account_journal journal
WHERE journal.payment_credit_account_id in %(credit_account)s
OR journal.payment_debit_account_id in %(debit_account)s ;
''', {
'credit_account': tuple(accounts.ids),
'debit_account': tuple(accounts.ids)
})
rows = self._cr.fetchall()
if rows:
journals = self.env['account.journal'].browse([r[0] for r in rows])
raise ValidationError(_(
"This account is configured in %(journal_names)s journal(s) (ids %(journal_ids)s) as payment debit or credit account. This means that this account's type should be reconcilable.",
journal_names=journals.mapped('display_name'),
journal_ids=journals.ids
))
@api.depends('code')
def _compute_account_root(self):
# this computes the first 2 digits of the account.
+10 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import tagged
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError
@tagged('post_install', '-at_install')
@@ -126,3 +126,12 @@ class TestAccountAccount(AccountTestInvoicingCommon):
# Try to set the account as a not-reconcile one.
with self.assertRaises(UserError), self.cr.savepoint():
account.reconcile = False
def test_toggle_reconcile_outstanding_account(self):
''' Test the feature when the user sets an account as not reconcilable when a journal
is configured with this account as the payment credit or debit account.
Since such an account should be reconcilable by nature, a ValidationError is raised.'''
with self.assertRaises(ValidationError), self.cr.savepoint():
self.company_data['default_journal_bank'].payment_debit_account_id.reconcile = False
with self.assertRaises(ValidationError), self.cr.savepoint():
self.company_data['default_journal_bank'].payment_credit_account_id.reconcile = False
@@ -173,6 +173,7 @@
<field name="id" invisible="1"/>
<field name="is_move_sent" invisible="1"/>
<field name="is_reconciled" invisible="1"/>
<field name="is_matched" invisible="1"/>
<field name="payment_method_code" invisible="1"/>
<field name="show_partner_bank_account" invisible="1"/>
<field name="require_partner_bank_account" invisible="1"/>