From 67d82b875cddba7bf28c3f4eba295df31dce3d48 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Mon, 19 Aug 2019 13:09:24 +0000 Subject: [PATCH] [FIX] account: round balance in the default_get of account move lines Edit journal entries (account.move). Create a new line. Credit and debit values are filled in with the default get. Conveniently, if lines_ids is given in context this computes the right value to balance existing move lines. However, this is done by float operations. Let e be the resulting epsilon in balance. As a result a new line may contain e, 0 for credit, debit (or respectively). If the user fills in the 0 value with v, then the new line contains e, v. This violates the constraint that exactly one of the two values should be nonzero. We get the currency from the journal to round adequately the balance. opw 2046137 closes odoo/odoo#35815 Signed-off-by: Nans Lefebvre (len) --- addons/account/models/account_move.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index da616cc63b7..522ea243542 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -489,6 +489,10 @@ class AccountMoveLine(models.Model): for line in self.move_id.resolve_2many_commands( 'line_ids', self._context['line_ids'], fields=['credit', 'debit']): balance += line.get('debit', 0) - line.get('credit', 0) + # if we are here, line_ids is in context, so journal_id should also be. + currency = self._context.get('journal_id') and self.browse(self._context['journal_id']).company_id.currency_id + if currency: + balance = currency.round(balance) if balance < 0: rec.update({'debit': -balance}) if balance > 0: