Commit e8b41f91 authored by Jérome Perrin's avatar Jérome Perrin

trade: split "Lines Report" in activities

Instead of generating the report in one big activity, split the calculation
in several batches, so that the processing can be distributed on zope nodes.

The limit for the number of lines was also increased from 10000 to 100000
parent ecb51c7a
Pipeline #13341 passed with stage
in 0 seconds
......@@ -2,22 +2,6 @@ from Products.PythonScripts.standard import Object
line_list = []
portal = context.getPortalObject()
# XXX use a larger limit
saved_selection_params = context.getPortalObject().portal_selections.getSelectionParamsFor(module_selection_name)
selection_params = saved_selection_params.copy()
selection_params['limit'] = 10000
context.getPortalObject().portal_selections.setSelectionParamsFor(module_selection_name, selection_params)
try:
checked_uid_list = portal.portal_selections.getSelectionCheckedUidsFor(module_selection_name)
if checked_uid_list:
getObject = portal.portal_catalog.getObject
delivery_list = [getObject(uid) for uid in checked_uid_list]
else:
delivery_list = portal.portal_selections.callSelectionFor(module_selection_name, context=context)
finally:
context.getPortalObject().portal_selections.setSelectionParamsFor(module_selection_name, saved_selection_params)
account_title_cache = {}
def getAccountTitle(relative_url):
try:
......@@ -32,7 +16,7 @@ def getAccountTitle(relative_url):
return title
for delivery in delivery_list:
for delivery in portal.portal_catalog(uid=uid_list or -1):
delivery = delivery.getObject()
for movement in delivery.getMovementList(portal_type=portal_type):
line_list.append(Object(
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>portal_type, module_selection_name, **kw</string> </value>
<value> <string>uid_list, portal_type, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
from Products.ERP5Form.Report import ReportSection
portal = context.getPortalObject()
request = container.REQUEST
return ReportSection(form_id='DeliveryModule_viewDeliveryLineList',
module_selection_name = request['selection_name']
# so that ods style does not repeat header on each section
request.set('merge_report_section_list', 1)
# XXX use a larger limit
saved_selection_params = portal.portal_selections.getSelectionParamsFor(module_selection_name)
selection_params = saved_selection_params.copy()
selection_params['limit'] = 100000
context.getPortalObject().portal_selections.setSelectionParamsFor(module_selection_name, selection_params)
report_section_list = []
try:
all_uid_list = portal.portal_selections.getSelectionCheckedUidsFor(module_selection_name)
if not all_uid_list:
all_uid_list = [ x.uid for x in
portal.portal_selections.callSelectionFor(module_selection_name, context=context)]
# split in chunks
batch_size = 1000
for uid_list in [all_uid_list[x:x+batch_size] for x in xrange(0, len(all_uid_list), batch_size)]:
report_section_list.append(
ReportSection(form_id='DeliveryModule_viewDeliveryLineList',
path=context.getPhysicalPath(),
selection_params=dict(portal_type=request['portal_type'],
module_selection_name=request['selection_name'])),
uid_list=uid_list,
module_selection_name=module_selection_name)))
return report_section_list
finally:
context.getPortalObject().portal_selections.setSelectionParamsFor(module_selection_name, saved_selection_params)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment