From 77be3d8b396f31adfa11d2cd10a22ee3a7f27883 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 7 Jun 2017 15:49:32 +0200 Subject: [PATCH] [FIX] account: avoid duplicated move name Commits 9365482df05 and 8fc81b871debc2 attempted to prevent the creation of two moves with the same name during reconciliation. It works in most cases, but it is still possible to reconcile the same statement line with more than one line. We add an extra check to make sure duplicate never happen. opw-742018 --- addons/account/models/account_bank_statement.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index c9634d5f270..e49546e31e7 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -891,6 +891,10 @@ class AccountBankStatementLine(models.Model): # Create the move self.sequence = self.statement_id.line_ids.ids.index(self.id) + 1 move_name = (self.statement_id.name or self.name) + "/" + str(self.sequence) + # Ensure no duplicate is created + if self.env['account.move'].search([('name', '=', move_name)]): + count = self.env['account.move'].search_count([('name', '=like', move_name + '/%')]) + move_name = u'{}/{}'.format(move_name, count + 1) move_vals = self._prepare_reconciliation_move(move_name) move = self.env['account.move'].create(move_vals) counterpart_moves = (counterpart_moves | move)