Commit 1596991d authored by Jérome Perrin's avatar Jérome Perrin Committed by Gabriel Monnerat

calendar: Group Presence Period repeat only for the duration of the Group Calendar Assignment

We should be able to configure a group calendar saying that the pattern
is "from 9:00 to 12:00, repeat every monday morning" with a group
calendar assignment saying "use this pattern from 01/01/2016 until
31/12/2016" and then create another group calendar assignment for 2017
without having to change the periodicity stop date on all presence
periods of the group calendar.

I think it should repeat from group calendar assignment's start date
until min(group calendar assignment's stop date, presence period's
periodicity stop date).

(cherry picked from commit b42a9c11)
parent e89bf2ee
......@@ -46,14 +46,36 @@ class GroupCalendarAssignment(PresencePeriod):
security.declareProtected(Permissions.AccessContentsInformation,
'getPeriodList')
def getPeriodList(self):
"""Returns the list of periods covered by this group calendar assignment.
The periods returned by this method are defined by:
- quantity
- resource
- start and stop dates
and optionally a periodicity definition, as defined by product/ERP5/mixin/periodicity_mixin.py
This can be scriptable using a type based method, for example to disable some non applicable periods.
The default implementation will consider all the periods from the associated group calendar,
only for the time frame of this calendar assignment.
"""
period_list = []
method = self._getTypeBasedMethod("getPeriodList")
if method is None:
group_calendar = self.getSpecialiseValue()
if group_calendar is not None:
period_list = group_calendar.objectValues(
portal_type=self.getPortalCalendarPeriodTypeList())
start_date = self.getStartDate()
stop_date = self.getStopDate()
period_list = []
for period in group_calendar.objectValues(
portal_type=self.getPortalCalendarPeriodTypeList()):
period_list.append(
period.asContext(
start_date=max(period.getStartDate(start_date), start_date),
periodicity_stop_date=min(
period.getPeriodicityStopDate(stop_date), stop_date))
)
else:
period_list = method()
return period_list
......@@ -62,13 +84,12 @@ class GroupCalendarAssignment(PresencePeriod):
result = []
start_date = self.getStartDate()
stop_date = self.getStopDate()
if not(None in (self.getDestinationUid(), start_date)):
if not(None in (self.getDestinationUid(), start_date, stop_date)):
period_list = self.getPeriodList()
if len(period_list):
for period in period_list:
for date_period_data in period._getDatePeriodDataList():
if date_period_data['start_date'].greaterThanEqualTo(start_date):
if stop_date is None or date_period_data['stop_date'].lessThanEqualTo(
stop_date):
result.append(date_period_data)
return result
\ No newline at end of file
for period in period_list:
for date_period_data in period._getDatePeriodDataList():
if date_period_data['start_date'].greaterThanEqualTo(start_date):
if stop_date is None or date_period_data['stop_date'].lessThanEqualTo(
stop_date):
result.append(date_period_data)
return result
......@@ -1512,6 +1512,111 @@ class TestCalendar(ERP5ReportTestCase):
[(m.getStartDate(), m.getStopDate()) for m in
available_time_movement_list])
def test_GroupCalendarRepeatUntilPeriodicity(self):
"""Test that when group presence period is repeated until periodicity stop date.
"""
node = self.portal.organisation_module.newContent(portal_type='Organisation',)
group_calendar = self.portal.group_calendar_module.newContent(
portal_type='Group Calendar')
group_calendar_period = group_calendar.newContent(
portal_type='Group Presence Period')
# 2008/01/01 was a Tuesday
group_calendar_period.setStartDate('2008/01/01 08:00:00 UTC')
group_calendar_period.setStopDate('2008/01/01 18:00:00 UTC')
group_calendar_period.setQuantity(10)
group_calendar_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
group_calendar_period.setPeriodicityWeekDayList(['Tuesday'])
# Repeat for two weeks only
group_calendar_period.setPeriodicityStopDate(DateTime('2008/01/09 00:00:00 UTC'))
self.tic()
assignment = self.portal.group_calendar_assignment_module.newContent(
specialise_value=group_calendar,
resource_value=self.portal.portal_categories.calendar_period_type.type1,
start_date=DateTime('2008/01/01 08:00:00 UTC'),
stop_date=DateTime('2008/01/31 20:00:00 UTC'), # repeat for 1 month
destination_value=node)
assignment.confirm()
self.tic()
# group calendar assignments is for one month, but since the presence period
# is only for two weeks, this assignment only repeat twice.
self.assertEqual([
( DateTime('2008/01/01 08:00:00 UTC'), DateTime('2008/01/01 18:00:00 UTC') ),
( DateTime('2008/01/08 08:00:00 UTC'), DateTime('2008/01/08 18:00:00 UTC') ), ],
[ (m.getStopDate(), m.getStartDate()) for m in assignment.asMovementList() ] )
def test_GroupCalendarWithoutPeriodicityStopDateRepeatUntilGroupCalendarAssignmentStopDate(self):
"""Test that when group presence period does not define periodicity stop date,
the group calendar assignment repeats until the stop date of the group calendar assignment.
"""
node = self.portal.organisation_module.newContent(portal_type='Organisation',)
group_calendar = self.portal.group_calendar_module.newContent(
portal_type='Group Calendar')
group_calendar_period = group_calendar.newContent(
portal_type='Group Presence Period')
# 2008/01/01 was a Tuesday
group_calendar_period.setStartDate('2008/01/01 08:00:00 UTC')
group_calendar_period.setStopDate('2008/01/01 18:00:00 UTC')
group_calendar_period.setQuantity(10)
group_calendar_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
group_calendar_period.setPeriodicityWeekDayList(['Tuesday'])
self.tic()
assignment = self.portal.group_calendar_assignment_module.newContent(
specialise_value=group_calendar,
resource_value=self.portal.portal_categories.calendar_period_type.type1,
start_date=DateTime('2008/01/01 08:00:00 UTC'),
stop_date=DateTime('2008/01/31 20:00:00 UTC'), # repeat for 1 month
destination_value=node)
assignment.confirm()
self.tic()
# in 2008/01 the Tuesday were:
self.assertEqual([
( DateTime('2008/01/01 08:00:00 UTC'), DateTime('2008/01/01 18:00:00 UTC') ),
( DateTime('2008/01/08 08:00:00 UTC'), DateTime('2008/01/08 18:00:00 UTC') ),
( DateTime('2008/01/15 08:00:00 UTC'), DateTime('2008/01/15 18:00:00 UTC') ),
( DateTime('2008/01/22 08:00:00 UTC'), DateTime('2008/01/22 18:00:00 UTC') ),
( DateTime('2008/01/29 08:00:00 UTC'), DateTime('2008/01/29 18:00:00 UTC') ), ],
[ (m.getStopDate(), m.getStartDate()) for m in assignment.asMovementList() ] )
def test_GroupCalendarWithoutPeriodicityStopDateAndGroupCalendarAssignmentWithoutStopDateDoNotRepeat(self):
"""Test that when group presence period does not define periodicity stop
date and group calendar assignment does not define stop date either the
periodicity does not repeat.
"""
node = self.portal.organisation_module.newContent(portal_type='Organisation',)
group_calendar = self.portal.group_calendar_module.newContent(
portal_type='Group Calendar')
group_calendar_period = group_calendar.newContent(
portal_type='Group Presence Period')
group_calendar_period.setStartDate('2008/01/01 08:00:00 UTC')
group_calendar_period.setStopDate('2008/01/01 18:00:00 UTC')
group_calendar_period.setQuantity(10)
group_calendar_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
self.tic()
assignment = self.portal.group_calendar_assignment_module.newContent(
specialise_value=group_calendar,
resource_value=self.portal.portal_categories.calendar_period_type.type1,
start_date=DateTime('2008/01/01 08:00:00 UTC'),
destination_value=node)
assignment.confirm()
self.tic()
self.assertEqual([], assignment.asMovementList())
def test_PersonModule_viewLeaveRequestReport(self):
# in this test, type1 is the type for presences, type2 & type3 are types
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment