From bcaba5fa7c919deceedad34236c81aef6d2da049 Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Thu, 6 Nov 2008 10:55:31 +0000
Subject: [PATCH] Make results consistent regarding date range in same Form
 Report

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24505 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Person_getPersonDetailedCareerList.xml        | 15 +++++++++++----
 .../Person_getPersonDetailedContributionList.xml  |  4 +++-
 .../Person_getPersonDetailedEventList.xml         | 12 +++++++++---
 .../your_at_date.xml                              |  8 +++++++-
 bt5/erp5_base/bt/revision                         |  2 +-
 5 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedCareerList.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedCareerList.xml
index 8ca4a01426..de16060711 100644
--- a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedCareerList.xml
+++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedCareerList.xml
@@ -55,17 +55,21 @@
             <key> <string>_body</string> </key>
             <value> <string encoding="cdata"><![CDATA[
 
+from Products.ERP5Type.DateUtils import atTheEndOfPeriod\n
 request = container.REQUEST\n
 from_date = request.get(\'from_date\', None)\n
 to_date = request.get(\'at_date\', None)\n
+aggregation_level = request.get(\'aggregation_level\', None)\n
+if to_date is not None:\n
+  to_date = atTheEndOfPeriod(to_date, period=aggregation_level)\n
 career_list = []\n
 if from_date is None and to_date is None:\n
   career_list = context.contentValues(filter={\'portal_type\':\'Career\'})\n
 else:\n
   for career in context.contentValues(filter={\'portal_type\':\'Career\'}):\n
     if from_date is not None and to_date is not None:\n
-      if career.getStartDate() >= from_date and career.getStartDate() <= to_date \\\n
-             or career.getStopDate() <= to_date and career.getStopDate() >= from_date \\\n
+      if career.getStartDate() >= from_date and career.getStartDate() < to_date \\\n
+             or career.getStopDate() < to_date and career.getStopDate() >= from_date \\\n
              or career.getStartDate() < from_date and career.getStopDate() > to_date:\n
         career_list.append(career)\n
     elif from_date is not None:\n
@@ -73,8 +77,8 @@ else:\n
              or career.getStopDate() >= from_date:\n
         career_list.append(career)\n
     elif to_date is not None:\n
-      if career.getStartDate() <= to_date \\\n
-             or career.getStopDate() <= to_date :\n
+      if career.getStartDate() < to_date \\\n
+             or career.getStopDate() < to_date :\n
         career_list.append(career)\n
 \n
 def date_cmp(a, b):\n
@@ -121,12 +125,15 @@ return career_list\n
                         <value>
                           <tuple>
                             <string>kw</string>
+                            <string>Products.ERP5Type.DateUtils</string>
+                            <string>atTheEndOfPeriod</string>
                             <string>_getattr_</string>
                             <string>container</string>
                             <string>request</string>
                             <string>None</string>
                             <string>from_date</string>
                             <string>to_date</string>
+                            <string>aggregation_level</string>
                             <string>career_list</string>
                             <string>context</string>
                             <string>_getiter_</string>
diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedContributionList.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedContributionList.xml
index 47aba639be..ec972e06cd 100644
--- a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedContributionList.xml
+++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedContributionList.xml
@@ -102,9 +102,10 @@ select_expression = \'DATE_FORMAT(creation_date, "%s") as date, portal_type\' %s
 group_by = \'DATE_FORMAT(creation_date, "%s"), portal_type\' %sql_format\n
 \n
 # count number of object created by the user for each type of document\n
+reference = request.get(\'person_reference_list\', context.getReference())\n
 result_list = context.portal_catalog.countResults(select_expression=select_expression,\n
                                                   portal_type=portal_type_list,limit=None,\n
-                                                  owner=context.getReference(),query=query,\n
+                                                  owner=reference,query=query,\n
                                                   group_by_expression=group_by)\n
 \n
 # build result dict per portal_type then period\n
@@ -229,6 +230,7 @@ return line_list\n
                             <string>_apply_</string>
                             <string>select_expression</string>
                             <string>group_by</string>
+                            <string>reference</string>
                             <string>result_list</string>
                             <string>portal_type_count_dict</string>
                             <string>result</string>
diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedEventList.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedEventList.xml
index b168c109c1..7fbf7aeff3 100644
--- a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedEventList.xml
+++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_getPersonDetailedEventList.xml
@@ -54,22 +54,25 @@
         <item>
             <key> <string>_body</string> </key>
             <value> <string>from Products.ZSQLCatalog.SQLCatalog import Query\n
+from Products.ERP5Type.DateUtils import atTheEndOfPeriod\n
 request = container.REQUEST\n
 portal = context.getPortalObject()\n
 from_date = request.get(\'from_date\', None)\n
 to_date = request.get(\'at_date\', None)\n
-\n
+aggregation_level = request.get(\'aggregation_level\', None)\n
+if to_date is not None:\n
+  to_date = atTheEndOfPeriod(to_date, period=aggregation_level)\n
 # build query based on dates\n
 query=None\n
 if from_date is not None and to_date is not None:  \n
   params = {"delivery.start_date":(from_date, to_date)}\n
-  query = Query(range="minngt", **params)\n
+  query = Query(range="minmax", **params)\n
 elif from_date is not None:\n
   params = {"delivery.start_date":from_date}\n
   query = Query(range="min", **params)\n
 elif to_date is not None:\n
   params = {"delivery.start_date":to_date}\n
-  query = Query(range="ngt", **params)\n
+  query = Query(range="max", **params)\n
 \n
 event_type_list = portal.getPortalEventTypeList()\n
 # get events where user is either source or destination\n
@@ -123,6 +126,8 @@ return event_list\n
                             <string>kw</string>
                             <string>Products.ZSQLCatalog.SQLCatalog</string>
                             <string>Query</string>
+                            <string>Products.ERP5Type.DateUtils</string>
+                            <string>atTheEndOfPeriod</string>
                             <string>_getattr_</string>
                             <string>container</string>
                             <string>request</string>
@@ -131,6 +136,7 @@ return event_list\n
                             <string>None</string>
                             <string>from_date</string>
                             <string>to_date</string>
+                            <string>aggregation_level</string>
                             <string>query</string>
                             <string>params</string>
                             <string>_apply_</string>
diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_viewPersonDetailedReport/your_at_date.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_viewPersonDetailedReport/your_at_date.xml
index a48fcda00f..49f30fa4a2 100644
--- a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_viewPersonDetailedReport/your_at_date.xml
+++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Person_viewPersonDetailedReport/your_at_date.xml
@@ -12,7 +12,9 @@
         <item>
             <key> <string>delegated_list</string> </key>
             <value>
-              <list/>
+              <list>
+                <string>title</string>
+              </list>
             </value>
         </item>
         <item>
@@ -90,6 +92,10 @@
                     <key> <string>target</string> </key>
                     <value> <string>Click to edit the target</string> </value>
                 </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string>To Date</string> </value>
+                </item>
               </dictionary>
             </value>
         </item>
diff --git a/bt5/erp5_base/bt/revision b/bt5/erp5_base/bt/revision
index a8114de9cf..2b808f36cf 100644
--- a/bt5/erp5_base/bt/revision
+++ b/bt5/erp5_base/bt/revision
@@ -1 +1 @@
-462
\ No newline at end of file
+463
\ No newline at end of file
-- 
2.30.9