Skip to content
Permalink
Browse files

[REF] account: Performance improve unreconcile process (_reverse_move):

_reverse_move presents a critical performance issue when
unreconcile moves with a lot of account_move_line.

The issue is that `account.move` and `account.move.line` models are triggering computed fields/methods for each new
`account.move.line` added, computing all lines again and again.

Making a factorial performance issue.

For each line the function try create cash basis entries for tax/base lines and this is combined with all the
fields compute that exists on the model so this introduce a performance problem

The issue is that `account.move` and `account.move.line` models are triggering
computed fields/methods for each new `account.move.line` created isolated,
computing all lines again and again.

e.g.
 _compute_matched_percentage at
https://github.com/odoo/odoo/blob/5e8289cfeaf52a1eac64bcc975b186f0b5f9594b/addons/account/models/account_move.py#L44-L62

Then for each line modified/created this compute is executed for all lines (not just the last one).

Now by using self.env.norecompute() and self.recompute() the problem was reduced.

Unreconciling an 'account.move' with 1576 lines with a payment takes almost 4
minutes when before this changes, the conciliation process seemed not to never
end.

Fix #30934
  • Loading branch information...
hugho-ad authored and moylop260 committed Feb 14, 2019
1 parent 1efc680 commit 52154f42d4260bc96874ef929aba185d03c2482a
Showing with 12 additions and 11 deletions.
  1. +12 −11 addons/account/models/account_move.py
@@ -232,16 +232,18 @@ def assert_balanced(self):
@api.multi
def _reverse_move(self, date=None, journal_id=None):
self.ensure_one()
reversed_move = self.copy(default={
'date': date,
'journal_id': journal_id.id if journal_id else self.journal_id.id,
'ref': _('reversal of: ') + self.name})
for acm_line in reversed_move.line_ids.with_context(check_move_validity=False):
acm_line.write({
'debit': acm_line.credit,
'credit': acm_line.debit,
'amount_currency': -acm_line.amount_currency
})
with self.env.norecompute():
reversed_move = self.copy(default={
'date': date,
'journal_id': journal_id.id if journal_id else self.journal_id.id,
'ref': _('reversal of: ') + self.name})
for acm_line in reversed_move.line_ids.with_context(check_move_validity=False):
acm_line.write({
'debit': acm_line.credit,
'credit': acm_line.debit,
'amount_currency': -acm_line.amount_currency
})
self.recompute()
return reversed_move

@api.multi
@@ -1747,7 +1749,6 @@ def create_tax_cash_basis_entry(self, percentage_before_rec):
'move_id': newly_created_move.id,
'partner_id': line.partner_id.id,
})

# Group by cash basis account and tax
self.env['account.move.line'].with_context(check_move_validity=False).create({
'name': line.name,

0 comments on commit 52154f4

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.