Commit f2e19ee6 authored by Sebastien Robin's avatar Sebastien Robin

2009-07-24 Seb

* Make the monthly report going aroung 2 times faster by caching some parts of the domain tree
* Use getInventory API for search task lines, we still get objects in the zodb in order to
get properties like start_date and stop_date
* Use ERP5Report in order to have a report similar to other ones and ERP5 and make it
more appropriate for unit test

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28178 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 440e8153
...@@ -77,16 +77,19 @@ month = here.getStartDate().month()\n ...@@ -77,16 +77,19 @@ month = here.getStartDate().month()\n
\n \n
if depth == 0:\n if depth == 0:\n
# Get start date and stop date from document\n # Get start date and stop date from document\n
start_date = here.getStartDate()\n from_date = request.get(\'from_date\')\n
stop_date = here.getStopDate()\n at_date = request.get(\'at_date\')\n
current_month = None\n current_month = None\n
# We must initialize start_date at the beginning of the month\n # We must initialize from_date at the beginning of the month\n
current_date = start_date\n current_date = from_date\n
month_dict = {}\n month_dict = request.form.get(\'month_dict\', None)\n
while current_date < stop_date:\n if month_dict is None:\n
if (current_date.year(), current_date.month()) not in month_dict:\n month_dict = {}\n
month_dict[(current_date.year(), current_date.month())] = 1\n while current_date < at_date:\n
current_date += 1\n if (current_date.year(), current_date.month()) not in month_dict:\n
month_dict[(current_date.year(), current_date.month())] = 1\n
current_date += 1\n
request.form[\'month_dict\'] = month_dict\n
\n \n
category_list = []\n category_list = []\n
i = 1\n i = 1\n
...@@ -203,8 +206,8 @@ return domain_list\n ...@@ -203,8 +206,8 @@ return domain_list\n
<string>category_list</string> <string>category_list</string>
<string>year</string> <string>year</string>
<string>month</string> <string>month</string>
<string>start_date</string> <string>from_date</string>
<string>stop_date</string> <string>at_date</string>
<string>current_month</string> <string>current_month</string>
<string>current_date</string> <string>current_date</string>
<string>month_dict</string> <string>month_dict</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>context.log(\'object_dict\', object_dict)\n
\n
context = context.asContext(object_dict=object_dict,\n
summary_dict=summary_dict,\n
column_list=column_list)\n
\n
return context\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>object_dict, summary_dict, column_list, **kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>object_dict</string>
<string>summary_dict</string>
<string>column_list</string>
<string>kw</string>
<string>_getattr_</string>
<string>context</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Project_getMonthlyReportContext</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -57,8 +57,6 @@ ...@@ -57,8 +57,6 @@
from Products.ZSQLCatalog.SQLCatalog import Query\n from Products.ZSQLCatalog.SQLCatalog import Query\n
request = context.REQUEST\n request = context.REQUEST\n
start_date = context.getStartDate()\n
stop_date = context.getStopDate()\n
\n \n
object_dict = {}\n object_dict = {}\n
\n \n
...@@ -69,53 +67,27 @@ worker_column_list = []\n ...@@ -69,53 +67,27 @@ worker_column_list = []\n
source_project_uid_list = [x.uid for x in context.portal_catalog(\n source_project_uid_list = [x.uid for x in context.portal_catalog(\n
relative_url=\'%s%%\' % context.getRelativeUrl())]\n relative_url=\'%s%%\' % context.getRelativeUrl())]\n
\n \n
from_date = request.get(\'from_date\', None)\n
if from_date is None:\n
from_date = context.getStartDate()\n
request.set(\'from_date\',from_date)\n
at_date = request.get(\'at_date\', None)\n
if at_date is None:\n
at_date = context.getStopDate()\n
request.set(\'at_date\',at_date)\n
simulation_state = request.get(\'simulation_state\', None)\n
\n \n
sql_kw = {}\n
if from_date is not None:\n
query_kw = {\'delivery.start_date\' : from_date,\n
\'range\' : \'min\'}\n
sql_kw[\'delivery.start_date\'] = Query(**query_kw)\n
if at_date is not None:\n
query_kw = {\'delivery.stop_date\' : at_date,\n
\'range\' : \'ngt\'}\n
sql_kw[\'delivery.stop_date\'] = Query(**query_kw)\n
\n \n
# Make sure to not include "confirmed tasks" in any case, because in\n # We will use inventory API in order to find all quantities\n
# this case we must take task reports\n result_list = context.portal_simulation.getInventoryList(\n
ignore_task = 0\n simulation_state = simulation_state,\n
if simulation_state is not None and len(simulation_state) > 0 :\n project_uid = source_project_uid_list,\n
task_simulation_state = [x for x in simulation_state if x != \'confirmed\']\n from_date=from_date,\n
if len(task_simulation_state) == 0:\n at_date=at_date)\n
ignore_task = 1\n
task_report_simulation_state = simulation_state\n
else:\n
task_simulation_state = context.getPortalDraftOrderStateList() + \\\n
context.getPortalPlannedOrderStateList()\n
task_report_simulation_state = None\n
\n
task_list = []\n
if not ignore_task:\n
task_list = [x.getObject() for x in \\\n
context.portal_catalog(\n
portal_type=\'Task\',\n
source_project_uid = source_project_uid_list,\n
simulation_state = task_simulation_state,\n
**sql_kw)]\n
task_list.extend([x.getObject() for x in \\\n
context.portal_catalog(\n
portal_type=\'Task Report\',\n
source_project_uid = source_project_uid_list,\n
simulation_state = task_report_simulation_state,\n
**sql_kw)])\n
\n
task_line_list = []\n
for task in task_list:\n
task_line_list.extend(task.objectValues(portal_type=(\'Task Line\', \'Task Report Line\')))\n
\n \n
monthly_worker_quantity_dict = {} # Used to get quantity per month and per worker\n monthly_worker_quantity_dict = {} # Used to get quantity per month and per worker\n
\n \n
\n for task_line in result_list:\n
for task_line in task_line_list:\n
# initialize some variables\n # initialize some variables\n
source = task_line.getSource()\n source = task_line.getSource()\n
if source is None:\n if source is None:\n
...@@ -187,14 +159,24 @@ for string_index, worker_quantity_dict in monthly_worker_quantity_dict.items():\ ...@@ -187,14 +159,24 @@ for string_index, worker_quantity_dict in monthly_worker_quantity_dict.items():\
temp_object.setProperty(source, quantity)\n temp_object.setProperty(source, quantity)\n
\n \n
column_list.extend(worker_column_list)\n column_list.extend(worker_column_list)\n
context = context.asContext(object_dict = object_dict,\n
summary_dict = summary_dict,\n
column_list = column_list,)\n
\n \n
selection_name = \'project_monthly_report_selection\'\n selection_name = \'project_monthly_report_selection\'\n
context.portal_selections.setListboxDisplayMode(request, \'ReportTreeMode\',\n context.portal_selections.setListboxDisplayMode(request, \'ReportTreeMode\',\n
selection_name=selection_name)\n selection_name=selection_name)\n
return context.Project_viewODSMonthlyReport()\n \n
result = []\n
from Products.ERP5Form.Report import ReportSection\n
param_dict = {}\n
\n
param_list = [object_dict, summary_dict, column_list]\n
\n
result.append(ReportSection(\n
path=context.getPhysicalPath(),\n
param_list=param_list,\n
method_id=\'Project_getMonthlyReportContext\',\n
listbox_display_mode=\'ReportTreeMode\',\n
form_id=\'Project_viewMonthlyReportData\'))\n
return result\n
]]></string> </value> ]]></string> </value>
...@@ -207,7 +189,7 @@ return context.Project_viewODSMonthlyReport()\n ...@@ -207,7 +189,7 @@ return context.Project_viewODSMonthlyReport()\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>from_date=None, at_date=None, simulation_state=None, **kw</string> </value> <value> <string>**kw</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -227,23 +209,18 @@ return context.Project_viewODSMonthlyReport()\n ...@@ -227,23 +209,18 @@ return context.Project_viewODSMonthlyReport()\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>3</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>from_date</string>
<string>at_date</string>
<string>simulation_state</string>
<string>kw</string> <string>kw</string>
<string>Products.ZSQLCatalog.SQLCatalog</string> <string>Products.ZSQLCatalog.SQLCatalog</string>
<string>Query</string> <string>Query</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>request</string> <string>request</string>
<string>start_date</string>
<string>stop_date</string>
<string>object_dict</string> <string>object_dict</string>
<string>column_list</string> <string>column_list</string>
<string>worker_column_list</string> <string>worker_column_list</string>
...@@ -252,18 +229,11 @@ return context.Project_viewODSMonthlyReport()\n ...@@ -252,18 +229,11 @@ return context.Project_viewODSMonthlyReport()\n
<string>_getiter_</string> <string>_getiter_</string>
<string>x</string> <string>x</string>
<string>source_project_uid_list</string> <string>source_project_uid_list</string>
<string>sql_kw</string>
<string>None</string> <string>None</string>
<string>query_kw</string> <string>from_date</string>
<string>_apply_</string> <string>at_date</string>
<string>_write_</string> <string>simulation_state</string>
<string>ignore_task</string> <string>result_list</string>
<string>len</string>
<string>task_simulation_state</string>
<string>task_report_simulation_state</string>
<string>task_list</string>
<string>task_line_list</string>
<string>task</string>
<string>monthly_worker_quantity_dict</string> <string>monthly_worker_quantity_dict</string>
<string>task_line</string> <string>task_line</string>
<string>source</string> <string>source</string>
...@@ -275,6 +245,7 @@ return context.Project_viewODSMonthlyReport()\n ...@@ -275,6 +245,7 @@ return context.Project_viewODSMonthlyReport()\n
<string>month_start_date</string> <string>month_start_date</string>
<string>date_string</string> <string>date_string</string>
<string>current_date</string> <string>current_date</string>
<string>_write_</string>
<string>_inplacevar_</string> <string>_inplacevar_</string>
<string>current_column</string> <string>current_column</string>
<string>project</string> <string>project</string>
...@@ -295,6 +266,11 @@ return context.Project_viewODSMonthlyReport()\n ...@@ -295,6 +266,11 @@ return context.Project_viewODSMonthlyReport()\n
<string>object_quantity</string> <string>object_quantity</string>
<string>summary_dict</string> <string>summary_dict</string>
<string>selection_name</string> <string>selection_name</string>
<string>result</string>
<string>Products.ERP5Form.Report</string>
<string>ReportSection</string>
<string>param_dict</string>
<string>param_list</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -306,16 +282,12 @@ return context.Project_viewODSMonthlyReport()\n ...@@ -306,16 +282,12 @@ return context.Project_viewODSMonthlyReport()\n
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <none/>
<none/>
<none/>
<none/>
</tuple>
</value> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Project_printAsODSMonthly</string> </value> <value> <string>Project_getMonthlyReportSectionList</string> </value>
</item> </item>
<item> <item>
<key> <string>warnings</string> </key> <key> <string>warnings</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ERP5Report" module="Products.ERP5Form.Report"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Project_viewMonthlyReport</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>Project_viewMonthlyReport</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>report_view</string> </value>
</item>
<item>
<key> <string>report_method</string> </key>
<value> <string>Project_getMonthlyReportSectionList</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Project_viewMonthlyReport</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Project_viewODSMonthlyReport</string> </value> <value> <string>Project_viewMonthlyReportData</string> </value>
</item> </item>
<item> <item>
<key> <string>method</string> </key> <key> <string>method</string> </key>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</item> </item>
<item> <item>
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>Project_printAsODSMonthly</string> </value> <value> <string>Project_viewMonthlyReport</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -128,6 +128,10 @@ ...@@ -128,6 +128,10 @@
<key> <string>update_action</string> </key> <key> <string>update_action</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
649 655
\ No newline at end of file \ No newline at end of file
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