[FIX] account: avoid duplicated move name

Commits 9365482df0 and 8fc81b871d 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
This commit is contained in:
Nicolas Martinelli
2017-06-08 14:11:26 +02:00
parent c4c9347b99
commit 77be3d8b39
@@ -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)