Commit fdc93391 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_research_item: add production modification

parent cf949f47
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 column_configuration_list is None:
column_configuration_list = ["research_item"]
inventory_kw = {}
if multiplier in (None, ''):
multiplier = 1.0
......@@ -10,94 +21,129 @@ if multiplier is None:
multiplier = 1
portal = context.getPortalObject()
portal_absolute_url = portal.absolute_url()
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())
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)
if len(task_report_state_set):
result_list.extend(portal.portal_simulation.getInventoryList(
simulation_state = [x for x in task_report_state_set],
portal_type='Task Report Line',
**inventory_kw))
summary_dict = {}
total_project_dict = {}
item_url_set = set()
for x in result_list:
aggregate_url = x.sub_variation_text
item_url = None
if aggregate_url:
if aggregate_url.startswith("aggregate"):
item_url = aggregate_url.split("aggregate/")[1]
if item_url is None:
item_url = "None"
item_url_set.add(item_url)
person_uid = x.node_uid
person_dict = summary_dict.setdefault(person_uid, {})
person_dict[item_url] = x.quantity * multiplier + person_dict.get(item_url, 0)
person_dict["total"] = x.quantity * multiplier + person_dict.get("total", 0)
total_project_dict[item_url] = x.quantity * multiplier + total_project_dict.get(item_url, 0)
total_project_dict["total"] = x.quantity * multiplier + total_project_dict.get("total", 0)
# now we group all results per person and we prepare one line in the listbox
# per person.
person_title_dict = {}
listbox_line_list = []
def genColumnIdFromRelativeUrlList(relative_url_list):
return "," + ",".join(relative_url_list)
def getColumnUrl(brain=None, column_id=None, **kw):
return getattr(brain, "%s_column_url" % column_id)
return getattr(brain, "{}_column_url".format(column_id))
absolute_url = portal.absolute_url()
column_configuration_title_dict = {
"research_item": "Research Item",
"client_project": "Client 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, ...}
summary_dict = {} # {node_uid: row_dict, ...} # row_dict = {column_id: cell_quantity, ...}
total_row_dict = {} # {column_id: total_column_quantity}
uid_title_dict = {} # {uid: title, ...}
if len(summary_dict):
for person in portal.portal_catalog(portal_type=("Person", "Organisation"), uid=summary_dict.keys(), select_list=["title"]):
person_title_dict[person.uid] = person.title
for person_uid in summary_dict.keys():
person_kw = summary_dict[person_uid]
person_kw["source_title"] = person_title_dict[person_uid]
person = portal.person_module.newContent(temp_object=1, **person_kw)
for item_url in summary_dict[person_uid].keys():
task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (absolute_url, person_uid)
if item_url == "None":
task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \
(ledger, )
else:
task_report_module_url += "&child_aggregate_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger)
person.edit(**{"%s_column_url" % item_url: task_report_module_url})
person.setProperty("getColumnUrl", getColumnUrl)
listbox_line_list.append(person)
# for each Task Lines / Task Report Lines
for x in result_list:
listbox_line_list.sort(key=lambda x: x.getProperty("source_title"))
# now add an extra line for total
person = portal.person_module.newContent(temp_object=1, source_title="Total", **total_project_dict)
listbox_line_list.append(person)
# fill column_id + column_relative_url_list_dict
# column_id could be a tuple of relative_url, but here dicts allow str only.
column_id = ""
relative_url_list = []
for column_type in column_configuration_list:
relative_url = ""
if column_type == "research_item":
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
item_title_dict = {}
if item_url_set:
for item in portal.portal_catalog(portal_type="Research Item", relative_url=list(item_url_set), select_list=["title","relative_url"]):
item_title_dict[item.relative_url] = item.title
item_title_dict["None"] = "undefined"
# 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)
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)
# define which property to display in columns
column_list = [("source_title", "Worker"),
("None", "Undefined"), ]
for item_url, item_title in sorted(item_title_dict.items(), key=lambda url_title: url_title[1]):
if item_url != 'None':
column_list.append((item_url, item_title))
column_list.append(("total", "Total"))
# fill relative_url_title_dict
relative_url_set = set()
for url_list in column_relative_url_list_dict.values():
for url in url_list:
if url:
relative_url_set.add(url)
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
# define which script to display url in columns
# fill listbox_line_list, i.e. convert summary_dict entries to temp objects
listbox_line_list = []
if len(summary_dict):
for brain in portal.portal_catalog(uid=summary_dict.keys(), select_list=["title"]):
uid_title_dict[brain.uid] = brain.title
for node_uid in summary_dict.keys():
edit_kw = summary_dict[node_uid]
edit_kw["source_title"] = uid_title_dict[node_uid]
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})
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)
# fill column_list + column_url_script_list
column_list = []
column_url_script_list = []
for item_url in item_title_dict.keys():
column_url_script_list.append((item_url, "getColumnUrl"))
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")]
context = context.asContext(column_list=column_list,
at_date=at_date,
......@@ -107,7 +153,7 @@ context = context.asContext(column_list=column_list,
ledger=ledger,
multiplier=multiplier,
listbox_line_list=listbox_line_list)
if batch_mode:
return context
return context.ResearchItemModule_viewResearchSummaryReportData()
......@@ -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, **kw</string> </value>
<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>
</item>
<item>
<key> <string>id</string> </key>
......
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