'Testing calendar hours scheduling'

def test_40_calendar_hours_scheduling(self):

    res = self.calendar.schedule_hours((-40), day_dt=self.date1.replace(minute=0, second=0))
    self.assertEqual(res[(-1)][0], Datetime.from_string('2013-02-12    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-1)][1], Datetime.from_string('2013-02-12    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-2)][0], Datetime.from_string('2013-02-08    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-2)][1], Datetime.from_string('2013-02-08    23:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-3)][0], Datetime.from_string('2013-02-08    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-3)][1], Datetime.from_string('2013-02-08    13:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-4)][0], Datetime.from_string('2013-02-05    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-4)][1], Datetime.from_string('2013-02-05    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-5)][0], Datetime.from_string('2013-02-01    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-5)][1], Datetime.from_string('2013-02-01    23:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-6)][0], Datetime.from_string('2013-02-01    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-6)][1], Datetime.from_string('2013-02-01    13:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-7)][0], Datetime.from_string('2013-01-29    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[(-7)][1], Datetime.from_string('2013-01-29    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    td = timedelta()
    for item in res:
        td += (item[1] - item[0])
    self.assertEqual((seconds(td) / 3600.0), 40.0, 'resource_calendar:    wrong    hours    scheduling')
    res = self.calendar.schedule_hours_get_date((-40), day_dt=self.date1.replace(minute=0, second=0))
    self.assertEqual(res, Datetime.from_string('2013-01-29    09:00:00'))
    res = self.calendar.schedule_hours(40, day_dt=self.date1.replace(minute=0, second=0))
    self.assertEqual(res[0][0], Datetime.from_string('2013-02-12    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[0][1], Datetime.from_string('2013-02-12    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[1][0], Datetime.from_string('2013-02-15    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[1][1], Datetime.from_string('2013-02-15    13:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[2][0], Datetime.from_string('2013-02-15    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[2][1], Datetime.from_string('2013-02-15    23:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[3][0], Datetime.from_string('2013-02-19    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[3][1], Datetime.from_string('2013-02-19    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[4][0], Datetime.from_string('2013-02-22    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[4][1], Datetime.from_string('2013-02-22    13:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[5][0], Datetime.from_string('2013-02-22    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[5][1], Datetime.from_string('2013-02-22    23:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[6][0], Datetime.from_string('2013-02-26    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[6][1], Datetime.from_string('2013-02-26    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    td = timedelta()
    for item in res:
        td += (item[1] - item[0])
    self.assertEqual((seconds(td) / 3600.0), 40.0, 'resource_calendar:    wrong    hours    scheduling')
    res = self.calendar.schedule_hours_get_date(40, day_dt=self.date1.replace(minute=0, second=0))
    self.assertEqual(res, Datetime.from_string('2013-02-26    09:00:00'))
    res = self.calendar.schedule_hours(40, day_dt=self.date1.replace(minute=0, second=0), compute_leaves=True, resource_id=self.resource1_id)
    self.assertEqual(res[0][0], Datetime.from_string('2013-02-12    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[0][1], Datetime.from_string('2013-02-12    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[1][0], Datetime.from_string('2013-02-15    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[1][1], Datetime.from_string('2013-02-15    13:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[2][0], Datetime.from_string('2013-02-15    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[2][1], Datetime.from_string('2013-02-15    23:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[3][0], Datetime.from_string('2013-02-19    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[3][1], Datetime.from_string('2013-02-19    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[4][0], Datetime.from_string('2013-02-19    12:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[4][1], Datetime.from_string('2013-02-19    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[5][0], Datetime.from_string('2013-02-22    08:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[5][1], Datetime.from_string('2013-02-22    09:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[6][0], Datetime.from_string('2013-02-22    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[6][1], Datetime.from_string('2013-02-22    23:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[7][0], Datetime.from_string('2013-03-01    11:30:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[7][1], Datetime.from_string('2013-03-01    13:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[8][0], Datetime.from_string('2013-03-01    16:00:00'), 'resource_calendar:    wrong    hours    scheduling')
    self.assertEqual(res[8][1], Datetime.from_string('2013-03-01    22:30:00'), 'resource_calendar:    wrong    hours    scheduling')
    td = timedelta()
    for item in res:
        td += (item[1] - item[0])
    self.assertEqual((seconds(td) / 3600.0), 40.0, 'resource_calendar:    wrong    hours    scheduling')
    res = self.calendar._interval_hours_get(self.date1.replace(hour=6, minute=0), (self.date2.replace(hour=23, minute=0) + relativedelta(days=7)), resource_id=self.resource1_id, exclude_leaves=True)
    self.assertEqual(res, 40.0, 'resource_calendar:    wrong    _interval_hours_get    compatibility    computation')
    res = self.calendar.get_working_hours(self.date1.replace(hour=6, minute=0), (self.date2.replace(hour=23, minute=0) + relativedelta(days=7)), compute_leaves=False, resource_id=self.resource1_id)
    self.assertEqual(res, 40.0, 'resource_calendar:    wrong    get_working_hours    computation')
    res = self.calendar._interval_hours_get(self.date1.replace(hour=6, minute=0), (self.date2.replace(hour=23, minute=0) + relativedelta(days=7)), resource_id=self.resource1_id, exclude_leaves=False)
    self.assertEqual(res, 33.0, 'resource_calendar:    wrong    _interval_hours_get    compatibility    computation')
    res = self.calendar.get_working_hours(self.date1.replace(hour=6, minute=0), (self.date2.replace(hour=23, minute=0) + relativedelta(days=7)), compute_leaves=True, resource_id=self.resource1_id)
    self.assertEqual(res, 33.0, 'resource_calendar:    wrong    get_working_hours    computation')
    res = self.ResourceCalendar.with_context(self.context).get_working_hours(self.date1.replace(hour=6, minute=0), self.date2.replace(hour=23, minute=0), compute_leaves=True, resource_id=self.resource1_id, default_interval=(8, 16))
    self.assertEqual(res, 32.0, 'resource_calendar:    wrong    get_working_hours    computation')
    self.att0_0_id = self.ResourceAttendance.with_context(self.context).create({'name': 'Att0', 'dayofweek': '0', 'hour_from': 7.5, 'hour_to': 12.5, 'calendar_id': self.calendar.id})
    self.att0_1_id = self.ResourceAttendance.with_context(self.context).create({'name': 'Att0', 'dayofweek': '0', 'hour_from': 13, 'hour_to': 14, 'calendar_id': self.calendar.id})
    date1 = Datetime.from_string('2013-02-11    07:30:00')
    date2 = Datetime.from_string('2013-02-11    14:00:00')
    res = self.calendar.get_working_hours(date1, date2, compute_leaves=False, resource_id=self.resource1_id)
    self.assertEqual(res, 6, 'resource_calendar:    wrong    get_working_hours    computation')
