From 0674b2a10c13ec3b1ef128d7168e6918fda4187e Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Wed, 9 Apr 2014 16:11:23 +0200
Subject: [PATCH] ERP5/Calendars: define group type list for calendars, partial
 design change

Calendar Assignments are now handled in a separate module, update
code in consequence
---
 product/ERP5/Document/Person.py         | 12 ++----------
 product/ERP5/Document/PresencePeriod.py |  6 +++---
 product/ERP5/ERP5Site.py                |  8 ++++++++
 product/ERP5/tests/testCalendar.py      |  6 +++---
 product/ERP5Type/ERP5Type.py            |  1 +
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/product/ERP5/Document/Person.py b/product/ERP5/Document/Person.py
index 142deed59a..a0cc8276e3 100644
--- a/product/ERP5/Document/Person.py
+++ b/product/ERP5/Document/Person.py
@@ -214,11 +214,7 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
 
       See SimulationTool.getAvailableTime
       """
-      assignment_list = self.contentValues(portal_type='Assignment')
-      calendar_uid_list = []
-      for assignment in assignment_list:
-        calendar_uid_list.extend(assignment.getCalendarUidList())
-      kw['node'] = [self.getUid()] + calendar_uid_list
+      kw['node'] = [self.getUid()]
 
       portal_simulation = self.getPortalObject().portal_simulation
       return portal_simulation.getAvailableTime(*args, **kw)
@@ -231,11 +227,7 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
       
       See SimulationTool.getAvailableTimeSequence
       """
-      assignment_list = self.contentValues(portal_type='Assignment')
-      calendar_uid_list = []
-      for assignment in assignment_list:
-        calendar_uid_list.extend(assignment.getCalendarUidList())
-      kw['node'] = [self.getUid()] + calendar_uid_list
+      kw['node'] = [self.getUid()]
 
       portal_simulation = self.getPortalObject().portal_simulation
       return portal_simulation.getAvailableTimeSequence(*args, **kw)
diff --git a/product/ERP5/Document/PresencePeriod.py b/product/ERP5/Document/PresencePeriod.py
index a3fdf18b78..5cfc51f187 100644
--- a/product/ERP5/Document/PresencePeriod.py
+++ b/product/ERP5/Document/PresencePeriod.py
@@ -102,9 +102,9 @@ class PresencePeriod(Movement, PeriodicityMixin):
     single destination.
     """
     result = []
-    for from_date, to_date in self._getDatePeriodList():
-      result.append(self.asContext(self, start_date=to_date,
-                                   stop_date=from_date))
+    if self.getSource() != None or self.getDestination() != None:
+      for date_period_data in self._getDatePeriodDataList():
+        result.append(self.asContext(self, **date_period_data))
     return result
 
   def _getDatePeriodDataList(self):
diff --git a/product/ERP5/ERP5Site.py b/product/ERP5/ERP5Site.py
index d62643faec..746eff56ca 100644
--- a/product/ERP5/ERP5Site.py
+++ b/product/ERP5/ERP5Site.py
@@ -1444,6 +1444,14 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
     """
     return self._getPortalGroupedTypeList('trade_model_path')
 
+  security.declareProtected(Permissions.AccessContentsInformation,
+                            'getPortalCalendarTypeList')
+  def getPortalCalendarTypeList(self):
+    """
+    Return calendar types.
+    """
+    return self._getPortalGroupedTypeList('calendar')
+
   security.declareProtected(Permissions.AccessContentsInformation,
                             'getPortalCalendarPeriodTypeList')
   def getPortalCalendarPeriodTypeList(self):
diff --git a/product/ERP5/tests/testCalendar.py b/product/ERP5/tests/testCalendar.py
index 25fb51a192..c2e87348f9 100644
--- a/product/ERP5/tests/testCalendar.py
+++ b/product/ERP5/tests/testCalendar.py
@@ -280,7 +280,7 @@ class TestCalendar(ERP5ReportTestCase):
     leave_request = sequence.get('leave_request')
     personal_leave_period = leave_request.newContent(
         portal_type=self.leave_request_period_portal_type,
-        resource='calendar_period_type/type1',
+        resource_value=self.portal.service_module.consulting_service
     )
     sequence.edit(
         personal_leave_period=personal_leave_period,
@@ -461,7 +461,7 @@ class TestCalendar(ERP5ReportTestCase):
     start_date = self.start_date
     stop_date = self.stop_date
     second_availability = int(stop_date) - int(start_date)
-    date_period_list = obj_to_check._getDatePeriodList()
+    date_period_list = obj_to_check._getDatePeriodDataList()
 
     # Check 1 period
     self.assertEqual(second_availability,
@@ -480,7 +480,7 @@ class TestCalendar(ERP5ReportTestCase):
     self.assertEqual(2 * second_availability,
                       person.getAvailableTime(
                                          from_date=start_date,
-                                         to_date=date_period_list[1][1]))
+                                         to_date=date_period_list[1]['stop_date']))
 #     # Check all periods
 #     self.assertEqual(len(date_period_list) * second_availability,
 #                       person.getAvailableTime())
diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py
index aa86bf1ecf..1d248588e5 100644
--- a/product/ERP5Type/ERP5Type.py
+++ b/product/ERP5Type/ERP5Type.py
@@ -307,6 +307,7 @@ class ERP5TypeInformation(XMLObject,
       # Movement Group
       'movement_group',
       # Calendar
+      'calendar',
       'calendar_period',
       # Project
       'project',
-- 
2.30.9