Merge lp:~avanzosc/ocb-addons/6.1 into lp:ocb-addons/6.1

Proposed by Daniel Campos (Avanzosc)
Status: Needs review
Proposed branch: lp:~avanzosc/ocb-addons/6.1
Merge into: lp:ocb-addons/6.1
Diff against target: 66 lines (+25/-6)
1 file modified
account/account.py (+25/-6)
To merge this branch: bzr merge lp:~avanzosc/ocb-addons/6.1
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza code review Approve
Review via email: mp+228159@code.launchpad.net

Description of the change

[FIX] OPW 591897 - ProgrammingError: memory exhausted when printing chart of accounts with large number of accounts (>20000)

From http://bazaar.launchpad.net/~openerp-dev/openobject-addons/7.0-opw-591897-acl/revision/9115

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Thanks for the fix, Dani.

LGTM. Regards.

review: Approve (code review)

Unmerged revisions

6848. By Daniel Campos (Avanzosc)

[FIX] OPW 591897 - ProgrammingError: memory exhausted when printing chart of accounts with large number of accounts (>20000)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account.py'
2--- account/account.py 2013-09-10 15:12:35 +0000
3+++ account/account.py 2014-07-24 15:40:50 +0000
4@@ -26,6 +26,7 @@
5
6 import netsvc
7 import pooler
8+import tools
9 from osv import fields, osv
10 import decimal_precision as dp
11 from tools.translate import _
12@@ -219,12 +220,13 @@
13 context=None, count=False):
14 if context is None:
15 context = {}
16+ split_args = []
17 pos = 0
18
19 while pos < len(args):
20
21 if args[pos][0] == 'code' and args[pos][1] in ('like', 'ilike') and args[pos][2]:
22- args[pos] = ('code', '=like', str(args[pos][2].replace('%', ''))+'%')
23+ args[pos] = ('code', '=like', tools.ustr(args[pos][2].replace('%', ''))+'%')
24 if args[pos][0] == 'journal_id':
25 if not args[pos][2]:
26 del args[pos]
27@@ -237,17 +239,34 @@
28 ids1 = super(account_account, self).search(cr, uid, [('user_type', 'in', ids3)])
29 ids1 += map(lambda x: x.id, jour.account_control_ids)
30 args[pos] = ('id', 'in', ids1)
31+
32+ # needed to ligthen request sent to postgres in chart of accounts : when requesting child ofg
33+ # large amount of accounts, the request is too long for being processed by postgres.
34+ # this mainly happens with leafs account
35+ if args[pos][0] == 'parent_id' and args[pos][1] == 'child_of' and args[pos][2] and isinstance(args[pos][2], list):
36+ split_size = 1000
37+ ids = args[pos][2][:]
38+ for i in range(len(ids)/split_size+1):
39+ split_args.append(args[:])
40+ split_args[i][pos] = (args[pos][0],args[pos][1],ids[split_size*i:split_size*(i+1)])
41+
42 pos += 1
43
44- if context and context.has_key('consolidate_children'): #add consolidated children of accounts
45+ if split_args:
46+ results = []
47+ for arg in split_args:
48+ results.extend(super(account_account, self).search(cr, uid, arg,
49+ offset, limit, order, context=context, count=count))
50+ ids = list(results)
51+ else:
52 ids = super(account_account, self).search(cr, uid, args, offset, limit,
53- order, context=context, count=count)
54+ order, context=context, count=count)
55+
56+ if context and 'consolidate_children' in context: #add consolidated children of accounts
57 for consolidate_child in self.browse(cr, uid, context['account_id'], context=context).child_consol_ids:
58 ids.append(consolidate_child.id)
59- return ids
60
61- return super(account_account, self).search(cr, uid, args, offset, limit,
62- order, context=context, count=count)
63+ return ids
64
65 def _get_children_and_consol(self, cr, uid, ids, context=None):
66 #this function search for all the children and all consolidated children (recursively) of the given account ids

Subscribers

People subscribed via source and target branches