From 08cea86c44aeb17f63bcab040653247be811faf1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 21 Oct 2014 11:09:51 +0000
Subject: [PATCH] Research Item Report: various fixes

---
 ...chItemModule_callResearchSummaryReport.xml | 35 ++++++++++---------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/bt5/erp5_research_item/SkinTemplateItem/portal_skins/erp5_research_item/ResearchItemModule_callResearchSummaryReport.xml b/bt5/erp5_research_item/SkinTemplateItem/portal_skins/erp5_research_item/ResearchItemModule_callResearchSummaryReport.xml
index f79499d7d7..954d9ee6cb 100644
--- a/bt5/erp5_research_item/SkinTemplateItem/portal_skins/erp5_research_item/ResearchItemModule_callResearchSummaryReport.xml
+++ b/bt5/erp5_research_item/SkinTemplateItem/portal_skins/erp5_research_item/ResearchItemModule_callResearchSummaryReport.xml
@@ -53,6 +53,8 @@
             <value> <string encoding="cdata"><![CDATA[
 
 inventory_kw = {}\n
+if multiplier in (None, \'\'):\n
+  multiplier = 1.0\n
 inventory_kw["at_date"] = at_date\n
 inventory_kw["from_date"] = from_date\n
 inventory_kw["quantity"] = "<0"\n
@@ -62,7 +64,6 @@ if multiplier is None:\n
   multiplier = 1\n
 \n
 portal = context.getPortalObject()\n
-\n
 simulation_state_set = set(simulation_state_list)\n
 # We will use inventory API in order to find all quantities\n
 before_confirmed_task_state_set = set(portal.getPortalPlannedOrderStateList() + \\\n
@@ -110,14 +111,14 @@ def getColumnUrl(brain=None, column_id=None, **kw):\n
 absolute_url = portal.absolute_url()\n
 \n
 if len(summary_dict):\n
-  for person in portal.portal_catalog(portal_type="Person", uid=summary_dict.keys(), select_list=["title"]):\n
+  for person in portal.portal_catalog(portal_type=("Person", "Organisation"), uid=summary_dict.keys(), select_list=["title"]):\n
     person_title_dict[person.uid] = person.title\n
   for person_uid in summary_dict.keys():\n
     person_kw = summary_dict[person_uid]\n
     person_kw["source_title"] = person_title_dict[person_uid]\n
     person = portal.person_module.newContent(temp_object=1, **person_kw)\n
     for item_url in summary_dict[person_uid].keys():\n
-      task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s" % (absolute_url, person_uid)\n
+      task_report_module_url = "%s/task_report_module/view?reset:int=1&default_source_uid=%s&title=%%" % (absolute_url, person_uid)\n
       if item_url == "None":\n
         task_report_module_url += "&child_aggregate_relative_url=%%3dNULL&left_join_list=child_aggregate_relative_url&journal_relative_url=journal/%s" % \\\n
                      (journal, )\n
@@ -128,6 +129,7 @@ if len(summary_dict):\n
     person.setProperty("getColumnUrl", getColumnUrl)\n
     listbox_line_list.append(person)\n
 \n
+listbox_line_list.sort(key=lambda x: x.getProperty("source_title"))\n
 # now add an extra line for total\n
 person = portal.person_module.newContent(temp_object=1, source_title="Total", **total_project_dict)\n
 listbox_line_list.append(person)\n
@@ -139,9 +141,11 @@ if item_url_set:\n
   item_title_dict["None"] = "undefined"\n
 \n
 # define which property to display in columns\n
-column_list = [("source_title", "Worker")]\n
-for item_url, item_title in item_title_dict.items():\n
-  column_list.append((item_url, item_title))\n
+column_list = [("source_title", "Worker"),\n
+                ("None", "Undefined"), ]\n
+for item_url, item_title in sorted(item_title_dict.items(), key=lambda url_title: url_title[1]):\n
+  if item_url != \'None\':\n
+    column_list.append((item_url, item_title))\n
 column_list.append(("total", "Total"))\n
 \n
 # define which script to display url in columns\n
@@ -149,16 +153,15 @@ column_url_script_list = []\n
 for item_url in item_title_dict.keys():\n
   column_url_script_list.append((item_url, "getColumnUrl"))\n
 \n
-context_kw = {}\n
-context_kw.update(column_list=column_list,\n
-                  at_date=at_date,\n
-                  from_date=from_date,\n
-                  simulation_state_list=simulation_state_list,\n
-                  column_url_script_list=column_url_script_list,\n
-                  journal=journal,\n
-                  multiplier=multiplier,\n
-                  listbox_line_list=listbox_line_list)\n
-context = context.getObject().asContext(**context_kw)\n
+context = context.asContext(column_list=column_list,\n
+                            at_date=at_date,\n
+                            from_date=from_date,\n
+                            simulation_state_list=simulation_state_list,\n
+                            column_url_script_list=column_url_script_list,\n
+                            journal=journal,\n
+                            multiplier=multiplier,\n
+                            listbox_line_list=listbox_line_list)\n
+                            \n
 if batch_mode:\n
   return context\n
 return context.ResearchItemModule_viewResearchSummaryReportData()\n
-- 
2.30.9