diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index aee7a4d4d4c..c77240b482d 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -848,14 +848,9 @@ class AccountBankStatementLine(models.Model): aml_dict['amount_currency'] = prorata_factor * self.amount aml_dict['currency_id'] = statement_currency.id - # Create the move line for the statement line using the total credit/debit of the counterpart - # This leaves out the amount already reconciled and avoids rounding errors from currency conversion - st_line_amount = sum(aml_dict['credit'] - aml_dict['debit'] for aml_dict in to_create) - aml_obj.with_context(check_move_validity=False).create(self._prepare_reconciliation_move_line(move, st_line_amount)) - # Create write-offs for aml_dict in new_aml_dicts: - aml_obj.with_context(check_move_validity=False).create(aml_dict, apply_taxes=False) + aml_obj.with_context(check_move_validity=False).create(aml_dict) # Create counterpart move lines and reconcile them for aml_dict in counterpart_aml_dicts: @@ -868,8 +863,14 @@ class AccountBankStatementLine(models.Model): aml_dict['currency_id'] = counterpart_move_line.currency_id.id aml_dict['amount_currency'] = company_currency.with_context(ctx).compute(aml_dict['debit'] - aml_dict['credit'], counterpart_move_line.currency_id) new_aml = aml_obj.with_context(check_move_validity=False).create(aml_dict) + (new_aml | counterpart_move_line).reconcile() + # Create the move line for the statement line using the bank statement line as the remaining amount + # This leaves out the amount already reconciled and avoids rounding errors from currency conversion + st_line_amount = -sum([x.balance for x in move.line_ids]) + aml_obj.with_context(check_move_validity=False).create(self._prepare_reconciliation_move_line(move, st_line_amount)) + move.post() counterpart_moves.assert_balanced() return counterpart_moves