From 862c24557628a0ed9d80db20d6191454b6a55def Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 19 Jul 2018 09:55:59 +0200 Subject: [PATCH] [FIX] account: default_get aml compute balance Create an account.move, create a line, then add an item to start to add a second aml The current balance of the move is put in debit (or credit) to help automatically making the second line Save the move. Edit the move Delete a line Add a new line Before this commit, the balance was not correctly computed because the default_get did not compute the balance on deleted lines The move ended up with wrong unbalanced new lines After this commit, the balance is computed with deleted lines taken into account --- addons/account/models/account_move.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index be4be9d3918..879fa6cb6d4 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -475,8 +475,11 @@ class AccountMoveLine(models.Model): #compute the default credit/debit of the next line in case of a manual entry balance = 0 for line in self._context['line_ids']: - if line[2]: + if line[2]: # in case of command 0: add a record with values balance += line[2].get('debit', 0) - line[2].get('credit', 0) + elif line[0] == 2: # line has been deleted + line_obj = self.browse(line[1]) + balance -= line_obj.debit - line_obj.credit if balance < 0: rec.update({'debit': -balance}) if balance > 0: