diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index be6ad0cb831..26c3340fed8 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -706,7 +706,10 @@ class AccountMoveLine(models.Model): for unreconciled lines, and something in-between for partially reconciled lines. """ need_residual_lines = self.filtered(lambda x: x.account_id.reconcile or x.account_id.account_type in ('asset_cash', 'liability_credit_card')) - stored_lines = need_residual_lines.filtered('id') + # Run the residual amount computation on all lines stored in the db. By + # using _origin, new records (with a NewId) are excluded and the + # computation works automagically for virtual onchange records as well. + stored_lines = need_residual_lines._origin if stored_lines: self.env['account.partial.reconcile'].flush_model() @@ -753,8 +756,8 @@ class AccountMoveLine(models.Model): foreign_curr = line.currency_id or comp_curr # Retrieve the amounts in both foreign/company currencies. If the record is 'new', the amounts_map is empty. - debit_amount, debit_amount_currency = amounts_map.get((line.id, 'debit'), (0.0, 0.0)) - credit_amount, credit_amount_currency = amounts_map.get((line.id, 'credit'), (0.0, 0.0)) + debit_amount, debit_amount_currency = amounts_map.get((line._origin.id, 'debit'), (0.0, 0.0)) + credit_amount, credit_amount_currency = amounts_map.get((line._origin.id, 'credit'), (0.0, 0.0)) # Subtract the values from the account.partial.reconcile to compute the residual amounts. line.amount_residual = comp_curr.round(line.balance - debit_amount + credit_amount)