Ejemplo n.º 1
0
 def test_calendar_timezone(self):
     # user in timezone UTC-9 asks for work hours
     #  Limits: between 2013-02-19 10:00:00 and 2013-02-26 15:30:00 (User TZ)
     #          between 2013-02-19 19:00:00 and 2013-02-27 00:30:00 (UTC)
     # Leaves:  between 2013-02-21 10:00:00 and 2013-02-26 12:00:00 (User TZ)
     # res: 19/02 (10-16 (beginning)) + 22/02 (0 (leave)) + 26/02 (12-15.30 (leave+ending))
     self.env.user.tz = 'US/Alaska'
     (self.leave1 | self.leave2 | self.leave3).unlink()
     leave = self.env['resource.calendar.leaves'].create({
         'name':
         'Timezoned Leaves',
         'calendar_id':
         self.calendar.id,
         'resource_id':
         self.resource1_id,
         'date_from':
         to_naive_utc(Datetime.from_string('2013-02-21 10:00:00'),
                      self.env.user),
         'date_to':
         to_naive_utc(Datetime.from_string('2013-02-26 12:00:00'),
                      self.env.user)
     })
     res = self.calendar.get_work_hours_count(
         to_naive_utc(Datetime.from_string('2013-02-19 10:00:00'),
                      self.env.user),
         to_naive_utc(Datetime.from_string('2013-02-26 15:30:00'),
                      self.env.user),
         self.resource1_id,
         compute_leaves=True)
     self.assertEqual(res, 9.5)
Ejemplo n.º 2
0
 def test_calendar_hours_scheduling_timezone(self):
     # user in timezone UTC-9 asks for work hours
     self.env.user.tz = 'US/Alaska'
     res = self.calendar.plan_hours(
         42,
         to_naive_utc(Datetime.from_string('2013-02-12 09:25:00'),
                      self.env.user))
     self.assertEqual(
         res,
         to_naive_utc(Datetime.from_string('2013-02-26 11:25:00'),
                      self.env.user))
Ejemplo n.º 3
0
 def test_calendar_days_scheduling_timezone(self):
     self.env.user.tz = 'US/Alaska'
     res = self.calendar.plan_days(
         5,
         to_naive_utc(Datetime.from_string('2013-02-12 09:08:07'),
                      self.env.user))
     self.assertEqual(
         to_naive_user_tz(res, self.env.user).date(),
         Datetime.from_string('2013-02-26 00:00:00').date())
Ejemplo n.º 4
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)
Ejemplo n.º 5
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')
Ejemplo n.º 6
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)