[FIX] account_reconciliation_widget: Multiple blue lines

In case of multiple blue lines, the code was not working properly, as
the old temporary journal entry was being deleted several times.

This situation is handled in this commit.
This commit is contained in:
Pedro M. Baeza
2023-05-16 14:47:31 +02:00
parent 729cc877b2
commit 2e961e1d64

View File

@@ -129,15 +129,18 @@ class AccountBankStatementLine(models.Model):
# but the generated move on statement post should be removed and link the
# payment one for not having double entry
# TODO: To mix already done payments with new ones. Not sure if possible.
old_move = self.move_id.with_context(force_delete=True)
for aml_rec in payment_aml_rec:
aml_rec.with_context(check_move_validity=False).write(
{"statement_line_id": self.id}
)
old_move = self.move_id.with_context(force_delete=True)
# This overwrites the value on each loop, so only one will be linked, but
# there's no better solution in this case
self.move_id = aml_rec.move_id.id
counterpart_moves |= aml_rec.move_id
if payment_aml_rec:
old_move.button_draft()
old_move.unlink()
counterpart_moves |= aml_rec.move_id
# Create move line(s). Either matching an existing journal entry
# (eg. invoice), in which case we reconcile the existing and the
# new move lines together, or being a write-off.