Commit 90fa1555 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_research_item: improve research report

1. add select by project
2. add select by type
3. fix column url
parent fdc93391
<dtml-var table_0>.uid = <dtml-var table_1>.uid
<dtml-var RELATED_QUERY_SEPARATOR>
<dtml-var table_2>.uid = <dtml-var table_1>.category_uid
<dtml-var RELATED_QUERY_SEPARATOR>
<dtml-var table_1>.base_category_uid = <dtml-var "portal_categories.source_project.getUid()">
AND <dtml-var table_0>.uid = <dtml-var table_1>.uid
AND <dtml-var table_0>.parent_uid = <dtml-var query_table>.uid
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL Method" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>table_0\n
table_1\n
table_2\n
RELATED_QUERY_SEPARATOR=" AND "\n
query_table="catalog"</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>z_related_child_source_project</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>SQL Method</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>z_related_child_source_project</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<key_list>
<key>child_source_project_relative_url | catalog,category,catalog/relative_url/z_related_child_source_project</key>
</key_list>
\ No newline at end of file
column_configuration_list = None
if column_configuration == "research_item":
column_configuration_list = ["research_item"]
elif column_configuration == "research_item_client_project":
column_configuration_list = ["research_item", "client_project"]
elif column_configuration == "client_project":
column_configuration_list = ["client_project"]
if not column_configuration_list:
column_configuration_list = ["research_item", "project"]
if column_configuration_list is None:
column_configuration_list = ["research_item"]
project_uid_list = []
for project in project_list:
project = context.restrictedTraverse(project)
project_uid_list.append(project.getUid())
for line in project.objectValues(portal_type='Project Line'):
project_uid_list.append(line.getUid())
inventory_kw = {}
if multiplier in (None, ''):
......@@ -17,8 +16,9 @@ inventory_kw["from_date"] = from_date
inventory_kw["quantity"] = "<0"
if ledger:
inventory_kw["ledger"] = "ledger/%s" % ledger
if multiplier is None:
multiplier = 1
if project_uid_list:
inventory_kw['project_uid'] = project_uid_list
portal = context.getPortalObject()
portal_absolute_url = portal.absolute_url()
......@@ -26,16 +26,20 @@ simulation_state_set = set(simulation_state_list)
# We will use inventory API in order to find all quantities
before_confirmed_task_state_set = set(portal.getPortalPlannedOrderStateList() + \
portal.getPortalDraftOrderStateList())
# get not confirmed task, so no related task report
task_state_set = simulation_state_set.intersection(before_confirmed_task_state_set)
result_list = []
context.log(task_state_set)
if len(task_state_set):
result_list.extend(portal.portal_simulation.getInventoryList(
simulation_state = [x for x in task_state_set],
portal_type=['Task Line'],
**inventory_kw))
task_report_state_set = simulation_state_set.difference(before_confirmed_task_state_set)
context.log(task_report_state_set)
# User can create draft task report directly
if 'draft' in before_confirmed_task_state_set:
task_report_state_set.add('draft')
if len(task_report_state_set):
result_list.extend(portal.portal_simulation.getInventoryList(
......@@ -44,13 +48,17 @@ if len(task_report_state_set):
**inventory_kw))
def genColumnIdFromRelativeUrlList(relative_url_list):
return "," + ",".join(relative_url_list)
if relative_url_list != ['']:
return "," + ",".join(relative_url_list)
return 'undefined'
def getColumnUrl(brain=None, column_id=None, **kw):
return getattr(brain, "{}_column_url".format(column_id))
column_configuration_title_dict = {
"research_item": "Research Item",
"client_project": "Client Project",
"project": "Project",
}
column_relative_url_list_dict = {} # {column_id: relative_url_list, ...} # relative_url_list = [relative_url x len(column_configuration_list)]
relative_url_title_dict = {"": "Undefined"} # {relative_url: title, ...}
......@@ -71,23 +79,27 @@ for x in result_list:
aggregate_url = x.sub_variation_text
if aggregate_url and aggregate_url.startswith("aggregate/"):
relative_url = aggregate_url[10:]
elif column_type == "client_project":
destination_project = x.getDestinationProject()
if destination_project is not None:
relative_url = destination_project
relative_url_list.append(relative_url)
column_id = genColumnIdFromRelativeUrlList(relative_url_list)
column_relative_url_list_dict[column_id] = relative_url_list
elif column_type == "project":
source_project = x.getSourceProject()
if source_project is not None:
relative_url = source_project
relative_url_list=[relative_url]
column_id = genColumnIdFromRelativeUrlList(relative_url_list)
column_relative_url_list_dict[column_id] = relative_url_list
# fill summary_dict + total_row_dict
node_uid = x.node_uid # could be Person / Organisation
row_dict = summary_dict.setdefault(node_uid, {})
value = x.quantity * multiplier
row_dict[column_id] = value + row_dict.get(column_id, 0)
node_uid = x.node_uid # could be Person / Organisation
row_dict = summary_dict.setdefault(node_uid, {})
value = x.quantity * multiplier
row_dict[column_id] = value + row_dict.get(column_id, 0)
total_row_dict[column_id] = value + total_row_dict.get(column_id, 0)
row_dict["total"] = value + row_dict.get("total", 0)
total_row_dict[column_id] = value + total_row_dict.get(column_id, 0)
total_row_dict["total"] = value + total_row_dict.get("total", 0)
# fill relative_url_title_dict
relative_url_set = set()
for url_list in column_relative_url_list_dict.values():
......@@ -97,7 +109,6 @@ for url_list in column_relative_url_list_dict.values():
if len(relative_url_set):
for brain in portal.portal_catalog(relative_url=relative_url_set, select_list=["title", "relative_url"]):
relative_url_title_dict[brain.relative_url] = brain.title
# fill listbox_line_list, i.e. convert summary_dict entries to temp objects
listbox_line_list = []
if len(summary_dict):
......@@ -109,27 +120,45 @@ if len(summary_dict):
row_object = portal.person_module.newContent(temp_object=1, **edit_kw)
row_object.setProperty("getColumnUrl", getColumnUrl)
# set properties for getColumnUrl
column_type = column_configuration_list[0]
if column_type == "research_item":
for column_id in column_relative_url_list_dict.keys():
if column_id not in summary_dict[node_uid]:
continue
task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (portal_absolute_url, node_uid)
item_url = column_relative_url_list_dict[column_id][0]
if item_url:
task_report_module_url += "&child_aggregate_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger)
else:
task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \
(ledger, )
row_object.edit(**{"{}_column_url".format(column_id): task_report_module_url})
elif column_type == "client_project":
for column_id in column_relative_url_list_dict.keys():
if column_id not in summary_dict[node_uid]:
continue
project_module_url = "{}/{}".format(portal_absolute_url, column_relative_url_list_dict[column_id][0])
row_object.edit(**{"{}_column_url".format(column_id): project_module_url})
for column_type in column_configuration_list:
if column_type == "research_item":
for column_id in column_relative_url_list_dict.keys():
if column_id not in summary_dict[node_uid]:
row_object.edit(**{"{}_column_url".format(column_id): ''})
continue
if column_id.startswith(',project_module'):
continue
task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (portal_absolute_url, node_uid)
item_url = column_relative_url_list_dict[column_id][0]
if item_url:
task_report_module_url += "&child_aggregate_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger)
else:
task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \
(ledger, )
row_object.edit(**{"{}_column_url".format(column_id): task_report_module_url})
elif column_type == "project":
for column_id in column_relative_url_list_dict.keys():
if column_id not in summary_dict[node_uid]:
row_object.edit(**{"{}_column_url".format(column_id): ''})
continue
if not column_id.startswith(',project'):
continue
project_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (portal_absolute_url, node_uid)
item_url = column_relative_url_list_dict[column_id][0]
if item_url:
if len(item_url.split('/')) == 2:
project_module_url += "&source_project_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger)
else:
project_module_url += "&child_source_project_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger)
row_object.edit(**{"{}_column_url".format(column_id): project_module_url})
listbox_line_list.append(row_object)
listbox_line_list.sort(key=lambda x: x.getProperty("source_title"))
row_object = portal.person_module.newContent(temp_object=1, source_title="Total", **total_row_dict)
listbox_line_list.append(row_object)
......@@ -137,13 +166,29 @@ listbox_line_list.append(row_object)
# fill column_list + column_url_script_list
column_list = []
column_url_script_list = []
for column_id, relative_url_list in column_relative_url_list_dict.items():
column_list.append((column_id, ", ".join([relative_url_title_dict[url] for url in relative_url_list])))
column_url_script_list.append((column_id, "getColumnUrl"))
column_list.sort(key=lambda o: o[1])
column_list = [("source_title", ", ".join([column_configuration_title_dict[t] for t in column_configuration_list]) + " per Worker")] + \
column_list + [("total", "Total")]
def compare(item1, item2):
key1 = item1[0]
key2 = item2[0]
if key1.split('/')[0] == key2.split('/')[0]:
tmp = len(key1)-len(key2)
if tmp == 0:
if key1 > key2:
return 1
return -1
return -tmp
if 'project_module' in key1:
return 1
return -1
column_list.sort(cmp=compare)
column_list = [("source_title", ", ".join([column_configuration_title_dict[t] for t in ['research_item']]) + " per Worker")] + \
column_list + [("total", "Total")]
context = context.asContext(column_list=column_list,
at_date=at_date,
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>at_date=None, from_date=None, simulation_state_list=None, ledger=None, multiplier=None, batch_mode=False, column_configuration=None, **kw</string> </value>
<value> <string>at_date=None, from_date=None, simulation_state_list=None, ledger=None, multiplier=None, batch_mode=False, column_configuration_list=None, project_list=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -75,6 +75,8 @@
<string>your_from_date</string>
<string>your_at_date</string>
<string>your_multiplier</string>
<string>your_column_configuration_list</string>
<string>your_project_list</string>
</list>
</value>
</item>
......
erp5_mysql_innodb/z_related_child_source_project
\ No newline at end of file
child_source_project_relative_url | catalog,category,catalog/relative_url/z_related_child_source_project
\ 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