[IMP] account: improve reconciliation speed

- Only invalidate cache for fields and records we modify
 - Rewrite query to be more efficient
 - Avoid o2m commands to be more efficient; write directly on reverse m2o
This commit is contained in:
Nicolas Seinlet 2016-05-12 11:41:13 +02:00 committed by Christophe Simonis
parent 6f29bfc181
commit f207ef5fae
3 changed files with 6 additions and 8 deletions

View File

@ -1339,7 +1339,7 @@ class account_move(osv.osv):
'SET state=%s '\
'WHERE id IN %s',
('posted', tuple(valid_moves),))
self.invalidate_cache(cr, uid, context=context)
self.invalidate_cache(cr, uid, ['state', ], valid_moves, context=context)
return True
def button_validate(self, cursor, user, ids, context=None):

View File

@ -629,9 +629,9 @@ class account_invoice(models.Model):
line_ids = self.move_line_id_payment_get()
if not line_ids:
return False
query = "SELECT reconcile_id FROM account_move_line WHERE id IN %s"
query = "SELECT count(*) FROM account_move_line WHERE reconcile_id IS NULL AND id IN %s"
self._cr.execute(query, (tuple(line_ids),))
return all(row[0] for row in self._cr.fetchall())
return self._cr.fetchone()[0] == 0
@api.multi
def button_reset_taxes(self):

View File

@ -1074,11 +1074,9 @@ class account_move_line(osv.osv):
# marking the lines as reconciled does not change their validity, so there is no need
# to revalidate their moves completely.
reconcile_context = dict(context, novalidate=True)
r_id = move_rec_obj.create(cr, uid, {
'type': type,
'line_id': map(lambda x: (4, x, False), ids),
'line_partial_ids': map(lambda x: (3, x, False), ids)
}, context=reconcile_context)
r_id = move_rec_obj.create(cr, uid, {'type': type}, context=reconcile_context)
self.write(cr, uid, ids, {'reconcile_id': r_id, 'reconcile_partial_id': False}, context=reconcile_context)
# the id of the move.reconcile is written in the move.line (self) by the create method above
# because of the way the line_id are defined: (4, x, False)
for id in ids: