From 52738a8df3f2ca3a0e89f671920aaccbe3c0d7ba Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 21 Feb 2014 14:43:46 +0100 Subject: [PATCH] [fix] mark moves for posting a bit at a time to avoid MemoryError --- account_move_batch_validate/account.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/account_move_batch_validate/account.py b/account_move_batch_validate/account.py index f9bee466c..9b84d5d40 100644 --- a/account_move_batch_validate/account.py +++ b/account_move_batch_validate/account.py @@ -27,6 +27,9 @@ from openerp.addons.connector.queue.job import job from openerp.addons.connector.session import ConnectorSession from openerp.addons.connector.queue.job import OpenERPJobStorage +# do a massive write on account moves BLOCK_SIZE at a time +BLOCK_SIZE = 1000 + class account_move(orm.Model): @@ -101,7 +104,15 @@ class account_move(orm.Model): """Mark a list of moves for delayed posting, and enqueue the jobs.""" if context is None: context = {} - self.write(cr, uid, move_ids, {'to_post': True}, context=context) + # For massive amounts of moves, this becomes necessary to avoid + # MemoryError's + for start in xrange(0, len(move_ids), BLOCK_SIZE): + self.write( + cr, + uid, + move_ids[start:start + BLOCK_SIZE], + {'to_post': True}, + context=context) self._delay_post_marked(cr, uid, eta=eta, context=context) def unmark_for_posting(self, cr, uid, move_ids, context=None):