Exemplo n.º 1
0
    def test_work_days_count(self):
        # user in timezone UTC-9 asks for work hours
        self.env.user.tz = 'US/Alaska'

        res = self.test.get_work_days_count(
            to_naive_utc(Datetime.from_string('2013-02-12 06:00:00'),
                         self.env.user),
            to_naive_utc(Datetime.from_string('2013-02-22 23:00:00'),
                         self.env.user))
        self.assertEqual(res, 3.75)  # generic leaves, 3 hours

        res = self.test.get_work_days_count(
            to_naive_utc(Datetime.from_string('2013-02-12 06:00:00'),
                         self.env.user),
            to_naive_utc(Datetime.from_string('2013-02-22 20:00:00'),
                         self.env.user))
        self.assertEqual(res, 3.5)  # last day is truncated of 3 hours on 12)

        self.env['resource.calendar.leaves'].create({
            'name':
            'Timezoned Leaves',
            'calendar_id':
            self.test.resource_calendar_id.id,
            'resource_id':
            self.test.resource_id.id,
            'date_from':
            to_naive_utc(Datetime.from_string('2013-02-13 10:00:00'),
                         self.env.user),
            'date_to':
            to_naive_utc(Datetime.from_string('2013-02-17 12:00:00'),
                         self.env.user)
        })

        res = self.test.get_work_days_count(
            to_naive_utc(Datetime.from_string('2013-02-12 06:00:00'),
                         self.env.user),
            to_naive_utc(Datetime.from_string('2013-02-22 20:00:00'),
                         self.env.user))
        self.assertEqual(
            res, 2.5
        )  # one day is on leave and last day is truncated of 3 hours on 12)
Exemplo n.º 2
0
 def test_calendar_hours_scheduling_timezone_2(self):
     # Call schedule_hours for a user in Autralia, Sydney (GMT+10)
     # Two cases:
     # - start at 2013-02-15 08:00:00 => 2013-02-14 21:00:00 in UTC
     # - start at 2013-02-15 11:00:00 => 2013-02-15 00:00:00 in UTC
     self.env.user.tz = 'Australia/Sydney'
     self.env['resource.calendar.attendance'].create({
         'name':
         'Day3 - 1',
         'dayofweek':
         '3',
         'hour_from':
         8,
         'hour_to':
         12,
         'calendar_id':
         self.calendar.id,
     })
     self.env['resource.calendar.attendance'].create({
         'name':
         'Day3 - 2',
         'dayofweek':
         '3',
         'hour_from':
         13,
         'hour_to':
         17,
         'calendar_id':
         self.calendar.id,
     })
     hours = 1.0 / 60.0
     for test_date in ['2013-02-15 08:00:00', '2013-02-15 11:00:00']:
         start_dt = Datetime.from_string(test_date)
         start_dt_utc = to_naive_utc(start_dt, self.env.user)
         res = self.calendar._schedule_hours(hours, start_dt_utc)
         self.assertEqual(
             [(start_dt_utc, start_dt_utc.replace(minute=1))], res,
             'resource_calendar: wrong schedule_hours computation')
Exemplo n.º 3
0
    def test_work_days_count_timezones_ultra(self):
        # user in timezone UTC+4 is attached to the resource and create leaves
        self.test.resource_id.write({
            'user_id': self.lost_user.id,
        })
        reunion_leave = self.env['resource.calendar.leaves'].sudo(
            self.lost_user).create({
                'name':
                'Timezoned Leaves',
                'calendar_id':
                self.test.resource_calendar_id.id,
                'resource_id':
                self.test.resource_id.id,
                'date_from':
                to_naive_utc(Datetime.from_string('2013-02-12 10:00:00'),
                             self.lost_user),
                'date_to':
                to_naive_utc(Datetime.from_string('2013-02-12 12:00:00'),
                             self.lost_user)
            })
        self.assertEqual(reunion_leave.tz, 'Indian/Reunion')

        # user in timezone UTC-9 read and manipulate leaves
        self.env.user.tz = 'US/Alaska'
        res = self.test.get_work_days_data(
            to_naive_utc(Datetime.from_string('2013-02-12 06:00:00'),
                         self.env.user),
            to_naive_utc(Datetime.from_string('2013-02-12 20:00:00'),
                         self.env.user))
        self.assertEqual(res['days'], 0.75)
        self.assertEqual(res['hours'], 6.0)

        # user in timezone UTC+4 read and manipulate leaves
        res = self.test.sudo(self.lost_user).get_work_days_data(
            to_naive_utc(Datetime.from_string('2013-02-12 06:00:00'),
                         self.env.user),
            to_naive_utc(Datetime.from_string('2013-02-12 20:00:00'),
                         self.env.user))
        self.assertEqual(res['days'], 0.75)
        self.assertEqual(res['hours'], 6.0)