Commit 1ce55c56 authored by Jérome Perrin's avatar Jérome Perrin

calendar: fix calendar exception when calendar does not repeat

Fix for [#20171205-E91759](https://nexedi.erp5.net/bug_module/20171205-E91759)

Basically extend the change from
24c836a7 to the case where there's an
exception, but the exception does not match and add tests to reproduce
the case.

/cc @seb @gabriel @georgios.dagkakis @Nicolas

/reviewed-on nexedi/erp5!630
parent 8e587fd7
......@@ -170,8 +170,9 @@ class PresencePeriod(Movement, PeriodicityMixin):
(current_exception_date < next_start_date.Date()):
# SQL method don't like iterator
# yield (next_start_date, next_start_date+duration)
result.append([next_start_date,
addToDate(next_start_date, second=second_duration)])
result.append({'start_date': next_start_date,
'stop_date': addToDate(next_start_date, second=second_duration),
'quantity': self.getQuantity()})
# Update the next exception date
if len(exception_date_list) != 0:
current_exception_date = exception_date_list.pop(0).Date()
......
......@@ -1512,6 +1512,117 @@ class TestCalendar(ERP5ReportTestCase):
[(m.getStartDate(), m.getStopDate()) for m in
available_time_movement_list])
def test_GroupCalendarPeriodExceptionWhenNoAvailability(self):
"""Having a group calendar exception on a day where the calendar does not
provide availability should index no availability for that day, without
error.
This is non-regression test for bug #20171205-E91759 , a problem in how
`asMovementList` build the list of movements for indexing.
"""
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('2016/01/01 09:00')
group_calendar_period.setStopDate('2016/01/01 16:00')
group_calendar_period.setPeriodicityStopDate('2016/02/01')
group_calendar_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
group_calendar_period.setPeriodicityWeekDayList(
('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', ))
group_calendar.confirm()
# Add exception on 2016/01/02 which is a Saturday - day where the calendar
# does not repeat.
#
# January 2016
# Su Mo Tu We Th Fr Sa
# 1 2
# 3 4 5 6 7 8 9
# 10 11 12 13 14 15 16
# 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30
# 31
group_calendar_period.newContent(
portal_type="Calendar Exception",
exception_date=DateTime(2016, 1, 2))
person = self.portal.person_module.newContent(portal_type='Person')
assignment = self.portal.group_calendar_assignment_module.newContent(
specialise_value=group_calendar,
resource_value=self.portal.service_module.consulting_service,
start_date=DateTime(2016, 1, 1).earliestTime(),
stop_date=DateTime(2016, 1, 31).latestTime(),
destination_value=person)
assignment.confirm()
self.tic()
self.assertTrue(assignment.asMovementList())
self.assertEqual(
7 * 60 * 60 * 21, # 7 hours per day, 21 "business days"
self.portal.portal_simulation.getInventory(
portal_type=self.portal.getPortalCalendarPeriodTypeList(),
from_date=DateTime(2016, 1, 1).earliestTime(),
to_date=DateTime(2016, 1, 31).latestTime(),
node_uid=person.getUid()))
def test_GroupCalendarPeriodExceptionTwoExceptionsOnSameDay(self):
"""Having two group calendar exceptions on the same day should index no
availability for that day, without error.
This is another non-regression test for bug #20171205-E91759 , with the
second exception, we are in the same scenario of having an exception for a
day where there's no availability.
"""
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('2016/01/01 09:00')
group_calendar_period.setStopDate('2016/01/01 16:00')
group_calendar_period.setPeriodicityStopDate('2016/02/01')
group_calendar_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
group_calendar_period.setPeriodicityWeekDayList(
('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', ))
group_calendar.confirm()
# Add two exceptions on 2016/01/01
#
# January 2016
# Su Mo Tu We Th Fr Sa
# 1 2
# 3 4 5 6 7 8 9
# 10 11 12 13 14 15 16
# 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30
# 31
group_calendar_period.newContent(
portal_type="Calendar Exception",
exception_date=DateTime(2016, 1, 1))
group_calendar_period.newContent(
portal_type="Calendar Exception",
exception_date=DateTime(2016, 1, 1))
person = self.portal.person_module.newContent(portal_type='Person')
assignment = self.portal.group_calendar_assignment_module.newContent(
specialise_value=group_calendar,
resource_value=self.portal.service_module.consulting_service,
start_date=DateTime(2016, 1, 1).earliestTime(),
stop_date=DateTime(2016, 1, 31).latestTime(),
destination_value=person)
assignment.confirm()
self.tic()
self.assertTrue(assignment.asMovementList())
self.assertEqual(
7 * 60 * 60 * 20, # 7 hours per day, 20 "business days" ( because 01/01 is not counted)
self.portal.portal_simulation.getInventory(
portal_type=self.portal.getPortalCalendarPeriodTypeList(),
from_date=DateTime(2016, 1, 1).earliestTime(),
to_date=DateTime(2016, 1, 31).latestTime(),
node_uid=person.getUid()))
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