From 02a204280bece5d54504454139e6b2a139bc6b8a Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Fri, 18 Jul 2008 13:15:56 +0000
Subject: [PATCH] improve workflow_report

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22558 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Folder_generateWorkflowReport.xml         | 62 ++++++++++++++++---
 .../Folder_viewWorkflowReport/listbox.xml     | 42 ++++++-------
 product/ERP5/bootstrap/erp5_core/bt/revision  |  2 +-
 3 files changed, 72 insertions(+), 34 deletions(-)

diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_generateWorkflowReport.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_generateWorkflowReport.xml
index 3e6579a0c1..924993af84 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_generateWorkflowReport.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_generateWorkflowReport.xml
@@ -66,29 +66,58 @@
         <item>
             <key> <string>_body</string> </key>
             <value> <string>listbox = []\n
-\n
+result_dict = {}\n
 portal_workflow = context.portal_workflow\n
 content_type_list = context.allowedContentTypes()\n
+content_type_list.sort()\n
 \n
 # XXX better implementation is required, but I do not know how to get workflows related to a portal type\n
-possible_state_name_list = ["validation_state", "simulation_state"]\n
+possible_state_name_list = (\'validation_state\',\n
+                            \'simulation_state\',\n
+                            \'causality_state\',\n
+                            \'invoice_state\',\n
+                            \'payment_state\',\n
+                            \'event_state\',\n
+                            \'opportunity_state\',\n
+                            \'immobilisation_state\',)\n
 \n
 for content_type in content_type_list:\n
   content_type_id = content_type.id\n
-\n
   for state_name in possible_state_name_list:\n
-    result_list = context.Base_zCountByWorkflowState(portal_type=content_type_id, state_name=state_name)\n
-\n
+    result_list = context.Base_zCountByWorkflowState(portal_type=content_type_id,\n
+                                                     state_name=state_name)\n
     if not ((len(result_list) == 1) and (result_list[0][0] is None)):\n
       for result in result_list:\n
+        portal_type_dict = result_dict.get(content_type_id, {})\n
+        count = portal_type_dict.get(result[0], 0) + result[1]\n
+        portal_type_dict.update({result[0]: count})\n
+        result_dict.update({content_type_id: portal_type_dict})\n
 \n
-        listbox.append({"portal_type":content_type_id,\n
-                        "state":result[0],\n
-                        "count":result[1] })\n
+state_list_dict = {}\n
+for portal_type in result_dict.keys():\n
+  listbox.append({\'portal_type\': portal_type,\n
+                  \'state\'      : \'\',\n
+                  \'count\'      : \'\'})\n
+  state_list = result_dict[portal_type].keys()\n
+  state_list.sort()\n
+  for state in state_list:\n
+    count = state_list_dict.get(state, 0) + result_dict[portal_type][state]\n
+    state_list_dict.update({state:count})\n
+    listbox.append({\'portal_type\': \'\',\n
+                    \'state\'      : state,\n
+                    \'count\'      : result_dict[portal_type][state]})\n
 \n
-context.Base_updateDialogForm(listbox = listbox,\n
-                              empty_line_number = 0)\n
+listbox.append({\'portal_type\': \'All\',\n
+                \'state\'      : \'\',\n
+                \'count\'      : \'\'})\n
+state_list = state_list_dict.keys()\n
+state_list.sort()\n
+for state in state_list:\n
+  listbox.append({\'portal_type\': \'\',\n
+                  \'state\'      : state,\n
+                  \'count\'      : state_list_dict[state]})\n
 \n
+context.Base_updateDialogForm(listbox=listbox, empty_line_number=0)\n
 return context.Folder_viewWorkflowReport()\n
 </string> </value>
         </item>
@@ -104,6 +133,12 @@ return context.Folder_viewWorkflowReport()\n
               <none/>
             </value>
         </item>
+        <item>
+            <key> <string>_owner</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
         <item>
             <key> <string>_params</string> </key>
             <value> <string></string> </value>
@@ -141,6 +176,7 @@ return context.Folder_viewWorkflowReport()\n
                         <value>
                           <tuple>
                             <string>listbox</string>
+                            <string>result_dict</string>
                             <string>_getattr_</string>
                             <string>context</string>
                             <string>portal_workflow</string>
@@ -155,6 +191,12 @@ return context.Folder_viewWorkflowReport()\n
                             <string>_getitem_</string>
                             <string>None</string>
                             <string>result</string>
+                            <string>portal_type_dict</string>
+                            <string>count</string>
+                            <string>state_list_dict</string>
+                            <string>portal_type</string>
+                            <string>state_list</string>
+                            <string>state</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_viewWorkflowReport/listbox.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_viewWorkflowReport/listbox.xml
index 0dc96a7340..c53b47094d 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_viewWorkflowReport/listbox.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_viewWorkflowReport/listbox.xml
@@ -3,11 +3,8 @@
   <record id="1" aka="AAAAAAAAAAE=">
     <pickle>
       <tuple>
-        <tuple>
-          <string>Products.ERP5Form.ListBox</string>
-          <string>ListBox</string>
-        </tuple>
-        <none/>
+        <global name="ListBox" module="Products.ERP5Form.ListBox"/>
+        <tuple/>
       </tuple>
     </pickle>
     <pickle>
@@ -325,10 +322,18 @@
                     <key> <string>alternate_name</string> </key>
                     <value> <string></string> </value>
                 </item>
+                <item>
+                    <key> <string>anchor</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
                 <item>
                     <key> <string>columns</string> </key>
                     <value>
                       <list>
+                        <tuple>
+                          <string>portal_type</string>
+                          <string>Portal Type</string>
+                        </tuple>
                         <tuple>
                           <string>state</string>
                           <string>State</string>
@@ -379,12 +384,7 @@
                 <item>
                     <key> <string>editable_columns</string> </key>
                     <value>
-                      <list>
-                        <tuple>
-                          <string>None</string>
-                          <string>None</string>
-                        </tuple>
-                      </list>
+                      <list/>
                     </value>
                 </item>
                 <item>
@@ -425,6 +425,10 @@
                       <list/>
                     </value>
                 </item>
+                <item>
+                    <key> <string>page_template</string> </key>
+                    <value> <string></string> </value>
+                </item>
                 <item>
                     <key> <string>portal_types</string> </key>
                     <value>
@@ -457,7 +461,7 @@
                 </item>
                 <item>
                     <key> <string>selection_name</string> </key>
-                    <value> <string></string> </value>
+                    <value> <string>folder_workflow_report_selection</string> </value>
                 </item>
                 <item>
                     <key> <string>sort</string> </key>
@@ -474,12 +478,7 @@
                 <item>
                     <key> <string>stat_columns</string> </key>
                     <value>
-                      <list>
-                        <tuple>
-                          <string>None</string>
-                          <string>None</string>
-                        </tuple>
-                      </list>
+                      <list/>
                     </value>
                 </item>
                 <item>
@@ -505,11 +504,8 @@
   <record id="2" aka="AAAAAAAAAAI=">
     <pickle>
       <tuple>
-        <tuple>
-          <string>Products.Formulator.MethodField</string>
-          <string>Method</string>
-        </tuple>
-        <none/>
+        <global name="Method" module="Products.Formulator.MethodField"/>
+        <tuple/>
       </tuple>
     </pickle>
     <pickle>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index 0f2ed730d5..f8f450742a 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-877
\ No newline at end of file
+878
\ No newline at end of file
-- 
2.30.9