From f00d6aaeafdc7206338e24b04b298705fd9d08dc Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 16 Sep 2019 12:41:09 +0000 Subject: [PATCH] [IMP] account: better logging of unbalanced entry Display the difference when an unbalanced journal entry is created to help pointing out the source of the issue. opw-2069673 closes odoo/odoo#37145 X-original-commit: d00e3158cd30067f7cc8d524eff81ccd6e620342 Signed-off-by: Nicolas Martinelli (nim) Co-authored-by: jev-odoo --- addons/account/i18n/account.pot | 6 ++++++ addons/account/models/account_move.py | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 91346b0d6a5..88640fdc1f0 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -3857,6 +3857,12 @@ msgstr "" msgid "Difference between the computed ending balance and the specified ending balance." msgstr "" +#. module: account +#: code:addons/account/models/account_move.py:408 +#, python-format +msgid "Difference debit - credit: " +msgstr "" + #. module: account #: model:ir.model,name:account.model_digest_digest msgid "Digest" diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 80d5dee694f..b17e624fcf7 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -430,7 +430,7 @@ class AccountMove(models.Model): # are already done. Then, this query MUST NOT depend of computed stored fields (e.g. balance). # It happens as the ORM makes the create with the 'no_recompute' statement. self._cr.execute(''' - SELECT line.move_id + SELECT line.move_id, ROUND(SUM(debit - credit), currency.decimal_places) FROM account_move_line line JOIN account_move move ON move.id = line.move_id JOIN account_journal journal ON journal.id = move.journal_id @@ -441,8 +441,12 @@ class AccountMove(models.Model): HAVING ROUND(SUM(debit - credit), currency.decimal_places) != 0.0; ''', [tuple(self.ids)]) - if self._cr.fetchone(): - raise UserError(_("Cannot create unbalanced journal entry.")) + res = self._cr.fetchone() + if res: + raise UserError( + _("Cannot create unbalanced journal entry.") + + "\n\n{}{}".format(_('Difference debit - credit: '), res[1]) + ) return True @api.multi