Skip to content
Snippets Groups Projects
Commit 80200333 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] account: statement line amount rounding

See comment in code.

opw-676924
parent 9365482d
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment