[FIX] account: statement line amount rounding

See comment in code.

opw-676924
This commit is contained in:
Nicolas Martinelli
2016-05-19 11:16:55 +02:00
parent 9365482df0
commit 80200333fc
@@ -392,6 +392,20 @@ class AccountBankStatementLine(models.Model):
if self.amount_currency != 0 and self.amount == 0:
raise ValidationError(_('If "Amount Currency" is specified, then "Amount" must be as well.'))
@api.model
def create(self, vals):
line = super(AccountBankStatementLine, self).create(vals)
# The most awesome fix you will ever see is below.
# Explanation: during a 'create', the 'convert_to_cache' method is not called. Moreover, at
# that point 'journal_currency_id' is not yet known since it is a related field. It means
# that the 'amount' field will not be properly rounded. The line below triggers a write on
# the 'amount' field, which will trigger the 'convert_to_cache' method, and ultimately round
# the field correctly.
# This is obviously an awful workaround, but at the time of writing, the ORM does not
# provide a clean mechanism to fix the issue.
line.amount = line.amount
return line
@api.multi
def unlink(self):
for line in self: