[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>
This commit is contained in:
Nans Lefebvre
2019-08-19 14:31:45 +00:00
parent 9e57917376
commit 67d82b875c
+4
View File
@@ -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: