From 80200333fcfe1b616b2b77ae0b2c9d92e16f3cfa Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 19 May 2016 08:56:29 +0200 Subject: [PATCH] [FIX] account: statement line amount rounding See comment in code. opw-676924 --- addons/account/models/account_bank_statement.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index e518964d7f2..1b809fe59a9 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -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: