From 1806ea18595bfb9a7660c5851ac84503ba56a042 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 22 Jan 2016 09:46:06 +0100 Subject: [PATCH] [FIX] account: write-off currency and sign The write-off currency should be the currency of the first account.move.line, since it is what is assumed in the interface. Moreover, the sign of amount_currency should match the constrain _check_currency_amount. opw-667137 --- addons/account/models/account_move.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 80921c6942f..ebfb5ffee30 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -706,11 +706,11 @@ class AccountMoveLine(models.Model): if len(new_mv_line_dicts) > 0: writeoff_lines = self.env['account.move.line'] company_currency = self[0].account_id.company_id.currency_id - account_currency = self[0].account_id.currency_id or company_currency + writeoff_currency = self[0].currency_id or company_currency for mv_line_dict in new_mv_line_dicts: - if account_currency != company_currency: - mv_line_dict['debit'] = account_currency.compute(mv_line_dict['debit'], company_currency) - mv_line_dict['credit'] = account_currency.compute(mv_line_dict['credit'], company_currency) + if writeoff_currency != company_currency: + mv_line_dict['debit'] = writeoff_currency.compute(mv_line_dict['debit'], company_currency) + mv_line_dict['credit'] = writeoff_currency.compute(mv_line_dict['credit'], company_currency) writeoff_lines += self._create_writeoff(mv_line_dict) (self + writeoff_lines).reconcile() @@ -831,10 +831,11 @@ class AccountMoveLine(models.Model): vals['debit'] = amount < 0 and abs(amount) or 0.0 vals['partner_id'] = self.env['res.partner']._find_accounting_partner(self[0].partner_id).id company_currency = self[0].account_id.company_id.currency_id - account_currency = self[0].account_id.currency_id or company_currency - if 'amount_currency' not in vals and account_currency != company_currency: - vals['currency_id'] = account_currency - vals['amount_currency'] = sum([r.amount_residual_currency for r in self]) + writeoff_currency = self[0].currency_id or company_currency + if 'amount_currency' not in vals and writeoff_currency != company_currency: + vals['currency_id'] = writeoff_currency.id + sign = 1 if vals['debit'] > 0 else -1 + vals['amount_currency'] = sign * abs(sum([r.amount_residual_currency for r in self])) # Writeoff line in the account of self first_line_dict = vals.copy()