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 not column_configuration_list:
if column_configuration == "research_item": column_configuration_list = ["research_item", "project"]
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 column_configuration_list is None: project_uid_list = []
column_configuration_list = ["research_item"] 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 = {} inventory_kw = {}
if multiplier in (None, ''): if multiplier in (None, ''):
...@@ -17,8 +16,9 @@ inventory_kw["from_date"] = from_date ...@@ -17,8 +16,9 @@ inventory_kw["from_date"] = from_date
inventory_kw["quantity"] = "<0" inventory_kw["quantity"] = "<0"
if ledger: if ledger:
inventory_kw["ledger"] = "ledger/%s" % 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 = context.getPortalObject()
portal_absolute_url = portal.absolute_url() portal_absolute_url = portal.absolute_url()
...@@ -26,16 +26,20 @@ simulation_state_set = set(simulation_state_list) ...@@ -26,16 +26,20 @@ simulation_state_set = set(simulation_state_list)
# We will use inventory API in order to find all quantities # We will use inventory API in order to find all quantities
before_confirmed_task_state_set = set(portal.getPortalPlannedOrderStateList() + \ before_confirmed_task_state_set = set(portal.getPortalPlannedOrderStateList() + \
portal.getPortalDraftOrderStateList()) portal.getPortalDraftOrderStateList())
# get not confirmed task, so no related task report
task_state_set = simulation_state_set.intersection(before_confirmed_task_state_set) task_state_set = simulation_state_set.intersection(before_confirmed_task_state_set)
result_list = [] result_list = []
context.log(task_state_set)
if len(task_state_set): if len(task_state_set):
result_list.extend(portal.portal_simulation.getInventoryList( result_list.extend(portal.portal_simulation.getInventoryList(
simulation_state = [x for x in task_state_set], simulation_state = [x for x in task_state_set],
portal_type=['Task Line'], portal_type=['Task Line'],
**inventory_kw)) **inventory_kw))
task_report_state_set = simulation_state_set.difference(before_confirmed_task_state_set) 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): if len(task_report_state_set):
result_list.extend(portal.portal_simulation.getInventoryList( result_list.extend(portal.portal_simulation.getInventoryList(
...@@ -44,13 +48,17 @@ if len(task_report_state_set): ...@@ -44,13 +48,17 @@ if len(task_report_state_set):
**inventory_kw)) **inventory_kw))
def genColumnIdFromRelativeUrlList(relative_url_list): 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): def getColumnUrl(brain=None, column_id=None, **kw):
return getattr(brain, "{}_column_url".format(column_id)) return getattr(brain, "{}_column_url".format(column_id))
column_configuration_title_dict = { column_configuration_title_dict = {
"research_item": "Research Item", "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)] 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, ...} relative_url_title_dict = {"": "Undefined"} # {relative_url: title, ...}
...@@ -71,23 +79,27 @@ for x in result_list: ...@@ -71,23 +79,27 @@ for x in result_list:
aggregate_url = x.sub_variation_text aggregate_url = x.sub_variation_text
if aggregate_url and aggregate_url.startswith("aggregate/"): if aggregate_url and aggregate_url.startswith("aggregate/"):
relative_url = aggregate_url[10:] relative_url = aggregate_url[10:]
elif column_type == "client_project": elif column_type == "project":
destination_project = x.getDestinationProject() source_project = x.getSourceProject()
if destination_project is not None: if source_project is not None:
relative_url = destination_project relative_url = source_project
relative_url_list.append(relative_url) relative_url_list=[relative_url]
column_id = genColumnIdFromRelativeUrlList(relative_url_list)
column_relative_url_list_dict[column_id] = relative_url_list column_id = genColumnIdFromRelativeUrlList(relative_url_list)
column_relative_url_list_dict[column_id] = relative_url_list
# fill summary_dict + total_row_dict # fill summary_dict + total_row_dict
node_uid = x.node_uid # could be Person / Organisation node_uid = x.node_uid # could be Person / Organisation
row_dict = summary_dict.setdefault(node_uid, {}) row_dict = summary_dict.setdefault(node_uid, {})
value = x.quantity * multiplier value = x.quantity * multiplier
row_dict[column_id] = value + row_dict.get(column_id, 0) 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) 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) total_row_dict["total"] = value + total_row_dict.get("total", 0)
# fill relative_url_title_dict # fill relative_url_title_dict
relative_url_set = set() relative_url_set = set()
for url_list in column_relative_url_list_dict.values(): for url_list in column_relative_url_list_dict.values():
...@@ -97,7 +109,6 @@ 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): if len(relative_url_set):
for brain in portal.portal_catalog(relative_url=relative_url_set, select_list=["title", "relative_url"]): 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 relative_url_title_dict[brain.relative_url] = brain.title
# fill listbox_line_list, i.e. convert summary_dict entries to temp objects # fill listbox_line_list, i.e. convert summary_dict entries to temp objects
listbox_line_list = [] listbox_line_list = []
if len(summary_dict): if len(summary_dict):
...@@ -109,27 +120,45 @@ 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 = portal.person_module.newContent(temp_object=1, **edit_kw)
row_object.setProperty("getColumnUrl", getColumnUrl) row_object.setProperty("getColumnUrl", getColumnUrl)
# set properties for getColumnUrl # set properties for getColumnUrl
column_type = column_configuration_list[0] for column_type in column_configuration_list:
if column_type == "research_item": if column_type == "research_item":
for column_id in column_relative_url_list_dict.keys(): for column_id in column_relative_url_list_dict.keys():
if column_id not in summary_dict[node_uid]: if column_id not in summary_dict[node_uid]:
continue row_object.edit(**{"{}_column_url".format(column_id): ''})
task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (portal_absolute_url, node_uid) continue
item_url = column_relative_url_list_dict[column_id][0] if column_id.startswith(',project_module'):
if item_url: continue
task_report_module_url += "&child_aggregate_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger) task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (portal_absolute_url, node_uid)
else: item_url = column_relative_url_list_dict[column_id][0]
task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \ if item_url:
(ledger, ) task_report_module_url += "&child_aggregate_relative_url=%s&ledger_relative_url=ledger/%s" % \
row_object.edit(**{"{}_column_url".format(column_id): task_report_module_url}) (item_url, ledger)
elif column_type == "client_project": else:
for column_id in column_relative_url_list_dict.keys(): task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \
if column_id not in summary_dict[node_uid]: (ledger, )
continue row_object.edit(**{"{}_column_url".format(column_id): task_report_module_url})
project_module_url = "{}/{}".format(portal_absolute_url, column_relative_url_list_dict[column_id][0]) elif column_type == "project":
row_object.edit(**{"{}_column_url".format(column_id): project_module_url}) 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.append(row_object)
listbox_line_list.sort(key=lambda x: x.getProperty("source_title")) 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) row_object = portal.person_module.newContent(temp_object=1, source_title="Total", **total_row_dict)
listbox_line_list.append(row_object) listbox_line_list.append(row_object)
...@@ -137,13 +166,29 @@ listbox_line_list.append(row_object) ...@@ -137,13 +166,29 @@ listbox_line_list.append(row_object)
# fill column_list + column_url_script_list # fill column_list + column_url_script_list
column_list = [] column_list = []
column_url_script_list = [] column_url_script_list = []
for column_id, relative_url_list in column_relative_url_list_dict.items(): 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_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_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, context = context.asContext(column_list=column_list,
at_date=at_date, at_date=at_date,
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -75,6 +75,8 @@ ...@@ -75,6 +75,8 @@
<string>your_from_date</string> <string>your_from_date</string>
<string>your_at_date</string> <string>your_at_date</string>
<string>your_multiplier</string> <string>your_multiplier</string>
<string>your_column_configuration_list</string>
<string>your_project_list</string>
</list> </list>
</value> </value>
</item> </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