From d8d1681a1359b7502cdf91ef667aa49b7998e215 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 23 Mar 2016 18:43:04 +0100 Subject: [PATCH] [FIX] account: check journal centralization performances This revision is related to 99d8cd6 Avoid to check the journal centralization mutliple times, for each move lines. Checking the journal centralization for each journal for each period just before the call to `super` is enough. Before this revision, if a large number of move lines was passed in the `ids` parameter of the `write` method, with all the same journal / period, this could lead to huge performances issues, the `_check_moves` being called a large number of times for the same journal and period couple, uselessly. opw-672797 --- addons/account/account_move_line.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 30e90dda379..8ce15834ab1 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -1221,6 +1221,7 @@ class account_move_line(osv.osv): todo_date = vals['date'] del vals['date'] + centralized_journals = [] for line in self.browse(cr, uid, ids, context=context): ctx = context.copy() if not ctx.get('journal_id'): @@ -1235,8 +1236,10 @@ class account_move_line(osv.osv): ctx['period_id'] = line.period_id.id #Check for centralisation journal = journal_obj.browse(cr, uid, ctx['journal_id'], context=ctx) - if journal.centralisation: - self._check_moves(cr, uid, context=ctx) + if journal.centralisation and (ctx['journal_id'], ctx['period_id']) not in centralized_journals: + centralized_journals.append((ctx['journal_id'], ctx['period_id'])) + for journal_period in centralized_journals: + self._check_moves(cr, uid, context=dict(ctx, journal_id=journal_period[0], period_id=journal_period[1])) result = super(account_move_line, self).write(cr, uid, ids, vals, context) if affects_move and check and not context.get('novalidate'):