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 = {} inventory_kw = {}
if multiplier in (None, ''): if multiplier in (None, ''):
multiplier = 1.0 multiplier = 1.0
...@@ -10,94 +21,129 @@ if multiplier is None: ...@@ -10,94 +21,129 @@ if multiplier is None:
multiplier = 1 multiplier = 1
portal = context.getPortalObject() portal = context.getPortalObject()
portal_absolute_url = portal.absolute_url()
simulation_state_set = set(simulation_state_list) 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())
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)
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(
simulation_state = [x for x in task_report_state_set], simulation_state = [x for x in task_report_state_set],
portal_type='Task Report Line', portal_type='Task Report Line',
**inventory_kw)) **inventory_kw))
summary_dict = {} def genColumnIdFromRelativeUrlList(relative_url_list):
total_project_dict = {} return "," + ",".join(relative_url_list)
item_url_set = set() 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",
}
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, ...}
# for each Task Lines / Task Report Lines
for x in result_list: for x in result_list:
# 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 aggregate_url = x.sub_variation_text
item_url = None if aggregate_url and aggregate_url.startswith("aggregate/"):
if aggregate_url: relative_url = aggregate_url[10:]
if aggregate_url.startswith("aggregate"): elif column_type == "client_project":
item_url = aggregate_url.split("aggregate/")[1] destination_project = x.getDestinationProject()
if item_url is None: if destination_project is not None:
item_url = "None" relative_url = destination_project
item_url_set.add(item_url) relative_url_list.append(relative_url)
person_uid = x.node_uid column_id = genColumnIdFromRelativeUrlList(relative_url_list)
person_dict = summary_dict.setdefault(person_uid, {}) column_relative_url_list_dict[column_id] = relative_url_list
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 # fill summary_dict + total_row_dict
# per person. node_uid = x.node_uid # could be Person / Organisation
person_title_dict = {} row_dict = summary_dict.setdefault(node_uid, {})
listbox_line_list = [] value = x.quantity * multiplier
def getColumnUrl(brain=None, column_id=None, **kw): row_dict[column_id] = value + row_dict.get(column_id, 0)
return getattr(brain, "%s_column_url" % column_id) 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)
absolute_url = portal.absolute_url() # 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
# fill listbox_line_list, i.e. convert summary_dict entries to temp objects
listbox_line_list = []
if len(summary_dict): if len(summary_dict):
for person in portal.portal_catalog(portal_type=("Person", "Organisation"), uid=summary_dict.keys(), select_list=["title"]): for brain in portal.portal_catalog(uid=summary_dict.keys(), select_list=["title"]):
person_title_dict[person.uid] = person.title uid_title_dict[brain.uid] = brain.title
for person_uid in summary_dict.keys(): for node_uid in summary_dict.keys():
person_kw = summary_dict[person_uid] edit_kw = summary_dict[node_uid]
person_kw["source_title"] = person_title_dict[person_uid] edit_kw["source_title"] = uid_title_dict[node_uid]
person = portal.person_module.newContent(temp_object=1, **person_kw) row_object = portal.person_module.newContent(temp_object=1, **edit_kw)
for item_url in summary_dict[person_uid].keys(): row_object.setProperty("getColumnUrl", getColumnUrl)
task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (absolute_url, person_uid) # set properties for getColumnUrl
if item_url == "None": column_type = column_configuration_list[0]
task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \ if column_type == "research_item":
(ledger, ) for column_id in column_relative_url_list_dict.keys():
else: 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" % \ task_report_module_url += "&child_aggregate_relative_url=%s&ledger_relative_url=ledger/%s" % \
(item_url, ledger) (item_url, ledger)
person.edit(**{"%s_column_url" % item_url: task_report_module_url}) else:
person.setProperty("getColumnUrl", getColumnUrl) task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&ledger_relative_url=ledger/%s" % \
listbox_line_list.append(person) (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")) listbox_line_list.sort(key=lambda x: x.getProperty("source_title"))
# now add an extra line for total row_object = portal.person_module.newContent(temp_object=1, source_title="Total", **total_row_dict)
person = portal.person_module.newContent(temp_object=1, source_title="Total", **total_project_dict) listbox_line_list.append(row_object)
listbox_line_list.append(person)
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"
# define which property to display in columns # fill column_list + column_url_script_list
column_list = [("source_title", "Worker"), column_list = []
("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"))
# define which script to display url in columns
column_url_script_list = [] column_url_script_list = []
for item_url in item_title_dict.keys(): for column_id, relative_url_list in column_relative_url_list_dict.items():
column_url_script_list.append((item_url, "getColumnUrl")) 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, 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, **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>
<item> <item>
<key> <string>id</string> </key> <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