From 136a760ea634dc631454a556b52f26539c07f9dd Mon Sep 17 00:00:00 2001
From: Gabriel Monnerat <gabriel@tiolive.com>
Date: Fri, 27 Sep 2013 14:29:39 +0200
Subject: [PATCH] Move changes on asMovementList method from PresencePeriod to
 GroupCalendarAssignment to keep Leave Period working as Expected.

---
 .../GroupCalendarAssignment.py                | 27 ++++++++++++++++++-
 bt5/erp5_calendar/bt/revision                 |  2 +-
 product/ERP5/Document/PresencePeriod.py       | 12 +++------
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/bt5/erp5_calendar/DocumentTemplateItem/GroupCalendarAssignment.py b/bt5/erp5_calendar/DocumentTemplateItem/GroupCalendarAssignment.py
index e2bbda37369..771b37de8f4 100644
--- a/bt5/erp5_calendar/DocumentTemplateItem/GroupCalendarAssignment.py
+++ b/bt5/erp5_calendar/DocumentTemplateItem/GroupCalendarAssignment.py
@@ -34,5 +34,30 @@ class GroupCalendarAssignment(PresencePeriod):
   meta_type = 'ERP5 Group Calendar Assignment'
   portal_type = 'Group Calendar Assignment'
 
+  # Declarative security
   security = ClassSecurityInfo()
-  security.declareObjectProtected(Permissions.AccessContentsInformation)
\ No newline at end of file
+  security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+  security.declareProtected( Permissions.AccessContentsInformation,
+                             'asMovementList')
+  def asMovementList(self):
+    """
+    Generate multiple movement from a single one.
+    It is used for cataloging a movement multiple time in
+    the movement/stock tables.
+
+    Ex: a movement have multiple destinations.
+    asMovementList returns a list a movement context with different
+    single destination.
+    """
+    result = []
+    if self.getDestinationUid() is None:
+      return result
+    group_calendar = self.getParentValue()
+    presence_period_list = group_calendar.objectValues(portal_type="Group Presence Period")
+    for presence_period in presence_period_list:
+      for from_date, to_date in presence_period._getDatePeriodList():
+        if from_date.greaterThanEqualTo(self.getStartDate()) and \
+            to_date.lessThanEqualTo(self.getStopDate() or group_calendar.getStopDate()):
+          result.append(self.asContext(self, start_date=to_date, stop_date=from_date))
+    return result
diff --git a/bt5/erp5_calendar/bt/revision b/bt5/erp5_calendar/bt/revision
index fd098d297eb..5f5d9b11ac6 100644
--- a/bt5/erp5_calendar/bt/revision
+++ b/bt5/erp5_calendar/bt/revision
@@ -1 +1 @@
-374
\ No newline at end of file
+375
\ No newline at end of file
diff --git a/product/ERP5/Document/PresencePeriod.py b/product/ERP5/Document/PresencePeriod.py
index 5edfa1937e5..d19d1347066 100644
--- a/product/ERP5/Document/PresencePeriod.py
+++ b/product/ERP5/Document/PresencePeriod.py
@@ -102,15 +102,9 @@ class PresencePeriod(Movement, PeriodicityMixin):
     single destination.
     """
     result = []
-    if self.getDestinationUid() is None:
-      return result
-    group_calendar = self.getParentValue()
-    presence_period_list = group_calendar.objectValues(portal_type="Group Presence Period")
-    for presence_period in presence_period_list:
-      for from_date, to_date in presence_period._getDatePeriodList():
-        if from_date.greaterThanEqualTo(self.getStartDate()) and to_date.lessThanEqualTo(self.getStopDate() or group_calendar.getStopDate()):
-          result.append(self.asContext(self, start_date=to_date, stop_date=from_date))
-
+    for from_date, to_date in self._getDatePeriodList():
+      result.append(self.asContext(self, start_date=to_date,
+                                   stop_date=from_date))
     return result
 
   def _getDatePeriodList(self):
-- 
2.30.9