summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNans Lefebvre <len@odoo.com>2019-08-19 13:09:24 +0000
committerNans Lefebvre <len@odoo.com>2019-08-19 14:31:45 +0000
commit67d82b875cddba7bf28c3f4eba295df31dce3d48 (patch)
tree1fd0ae5fc8e5c50a077dc5b0c9b8a4e2d97ec89a
parent9e579173762f281487a8ae988511355ce8b1a5cc (diff)
[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) <len@odoo.com>
-rw-r--r--addons/account/models/account_move.py4
1 files changed, 4 insertions, 0 deletions
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: