Exemple #1
0
 def test_calendar_working_hours_of_date(self):
     # Test: day1, beginning at 10:30 -> work from 10:30 (arrival) until 16:00
     wh = self.calendar.get_work_hours_count(
         Datetime.from_string('2013-02-19 10:30:00'),
         Datetime.from_string('2013-02-19 18:00:00'),
         self.resource1_id,
         compute_leaves=False)
     self.assertEqual(wh, 5.5)
Exemple #2
0
 def test_calendar_working_hours_leaves(self):
     # new API: resource and leaves
     # res: 2 weeks -> 40 hours - (3+4) leave hours
     res = self.calendar.get_work_hours_count(
         Datetime.from_string('2013-02-12 06:00:00'),
         Datetime.from_string('2013-02-22 23:00:00'),
         self.resource1_id,
         compute_leaves=True)
     self.assertEqual(res, 33.0)
Exemple #3
0
 def test_calendar_working_hours(self):
     # new API: resource without leaves
     # res: 2 weeks -> 40 hours
     res = self.calendar.get_work_hours_count(
         Datetime.from_string('2013-02-12 06:00:00'),
         Datetime.from_string('2013-02-22 23:00:00'),
         self.resource1_id,
         compute_leaves=False)
     self.assertEqual(res, 40.0)
Exemple #4
0
 def test_calendar_working_hours_count(self):
     calendar = self.env.ref('resource.resource_calendar_std_35h')
     res = calendar.get_work_hours_count(
         Datetime.from_string(
             '2017-05-03 14:03:00'),  # Wednesday (8:00-12:00, 13:00-16:00)
         Datetime.from_string(
             '2017-05-04 11:03:00'),  # Thursday (8:00-12:00, 13:00-16:00)
         resource_id=None,
         compute_leaves=False)
     self.assertEqual(res, 5.0)
Exemple #5
0
    def test_calendar_working_day_intervals_limited_attendances(self):
        """ Test attendances limited in time. """
        attendance = self.env['resource.calendar.attendance'].search([
            ('name', '=', 'Att3')
        ])
        attendance.write({
            'date_from': self.date2 + relativedelta(days=7),
            'date_to': False,
        })
        intervals = self.calendar._get_day_work_intervals(
            self.date2.date(), start_time=self.date2.time())
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-15 10:11:12'),
                          Datetime.from_string('2013-02-15 13:00:00')))

        attendance.write({
            'date_from': False,
            'date_to': self.date2 - relativedelta(days=7),
        })
        intervals = self.calendar._get_day_work_intervals(
            self.date2.date(), start_time=self.date2.time())
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-15 10:11:12'),
                          Datetime.from_string('2013-02-15 13:00:00')))

        attendance.write({
            'date_from': self.date2 + relativedelta(days=7),
            'date_to': self.date2 - relativedelta(days=7),
        })
        intervals = self.calendar._get_day_work_intervals(
            self.date2.date(), start_time=self.date2.time())
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-15 10:11:12'),
                          Datetime.from_string('2013-02-15 13:00:00')))

        attendance.write({
            'date_from': self.date2,
            'date_to': self.date2,
        })
        intervals = self.calendar._get_day_work_intervals(
            self.date2.date(), start_time=self.date2.time())
        self.assertEqual(len(intervals), 2)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-15 10:11:12'),
                          Datetime.from_string('2013-02-15 13:00:00')))
        self.assertEqual(intervals[1][:2],
                         (Datetime.from_string('2013-02-15 16:00:00'),
                          Datetime.from_string('2013-02-15 23:00:00')))
Exemple #6
0
    def test_calendar_working_day_intervals_no_leaves(self):
        # Test: day0 without leaves: 1 interval
        intervals = self.calendar._get_day_work_intervals(
            Date.from_string('2013-02-12'), start_time=time(9, 8, 7))
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-12 09:08:07'),
                          Datetime.from_string('2013-02-12 16:00:00')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_1)

        # Test: day1, beginning at 10:30 -> work from 10:30 (arrival) until 16:00
        intervals = self.calendar._get_day_work_intervals(
            Date.from_string('2013-02-19'), start_time=time(10, 30, 0))
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-19 10:30:00'),
                          Datetime.from_string('2013-02-19 16:00:00')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_1)

        # Test: day3 without leaves: 2 interval
        intervals = self.calendar._get_day_work_intervals(
            Date.from_string('2013-02-15'), start_time=time(10, 11, 12))
        self.assertEqual(len(intervals), 2)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-15 10:11:12'),
                          Datetime.from_string('2013-02-15 13:00:00')))
        self.assertEqual(intervals[1][:2],
                         (Datetime.from_string('2013-02-15 16:00:00'),
                          Datetime.from_string('2013-02-15 23:00:00')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_2)
        self.assertEqual(intervals[1][2]['attendances'], self.att_3)
Exemple #7
0
 def _check_session_timing(self):
     self.ensure_one()
     date_today = datetime.utcnow()
     session_start = Datetime.from_string(self.start_at)
     if not date_today - timedelta(hours=24) <= session_start:
         raise UserError(
             _("This session has been opened another day. To comply with the French law, you should close sessions on a daily basis. Please close session %s and open a new one."
               ) % self.name)
     return True
Exemple #8
0
    def test_calendar_working_day_intervals_leaves_generic(self):
        # Test: day0 with leaves outside range: 1 interval
        intervals = self.calendar._get_day_work_intervals(
            Date.from_string('2013-02-12'),
            start_time=time(7, 0, 0),
            compute_leaves=True)
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-12 08:00:00'),
                          Datetime.from_string('2013-02-12 16:00:00')))

        # Test: day0 with leaves: 2 intervals because of leave between 9 and 12, ending at 15:45:30
        intervals = self.calendar._get_day_work_intervals(
            Date.from_string('2013-02-19'),
            start_time=time(8, 15, 0),
            end_time=time(15, 45, 30),
            compute_leaves=True)
        self.assertEqual(len(intervals), 2)
        self.assertEqual(intervals[0][:2],
                         (Datetime.from_string('2013-02-19 08:15:00'),
                          Datetime.from_string('2013-02-19 09:00:00')))
        self.assertEqual(intervals[1][:2],
                         (Datetime.from_string('2013-02-19 12:00:00'),
                          Datetime.from_string('2013-02-19 15:45:30')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_1)
        self.assertEqual(intervals[0][2]['leaves'], self.leave1)
        self.assertEqual(intervals[1][2]['attendances'], self.att_1)
        self.assertEqual(intervals[0][2]['leaves'], self.leave1)
Exemple #9
0
    def _get_car_atn(self, acquisition_date, car_value, fuel_type, co2):
        # Compute the correction coefficient from the age of the car
        now = Datetime.from_string(Datetime.now())
        start = Datetime.from_string(acquisition_date)
        if start:
            number_of_month = (
                now.year - start.year) * 12.0 + now.month - start.month + int(
                    bool(now.day - start.day + 1))
            if number_of_month <= 12:
                age_coefficient = 1.00
            elif number_of_month <= 24:
                age_coefficient = 0.94
            elif number_of_month <= 36:
                age_coefficient = 0.88
            elif number_of_month <= 48:
                age_coefficient = 0.82
            elif number_of_month <= 60:
                age_coefficient = 0.76
            else:
                age_coefficient = 0.70
            car_value = car_value * age_coefficient
            # Compute atn value from corrected car_value
            magic_coeff = 6.0 / 7.0  # Don't ask me why
            if fuel_type == 'electric':
                atn = 0.0
            else:
                if fuel_type in ['diesel', 'hybrid']:
                    reference = 87.0
                else:
                    reference = 105.0

                if co2 <= reference:
                    atn = car_value * max(0.04,
                                          (0.055 - 0.001 *
                                           (reference - co2))) * magic_coeff
                else:
                    atn = car_value * min(0.18,
                                          (0.055 + 0.001 *
                                           (co2 - reference))) * magic_coeff
            return max(1280, atn) / 12.0
Exemple #10
0
def ctx_tz(record, field):
    res_lang = None
    ctx = record._context
    tz_name = pytz.timezone(ctx.get('tz') or record.env.user.tz)
    timestamp = Datetime.from_string(record[field])
    if ctx.get('lang'):
        res_lang = record.env['res.lang'].search([('code', '=', ctx['lang'])],
                                                 limit=1)
    if res_lang:
        timestamp = pytz.utc.localize(timestamp, is_dst=False)
        return datetime.strftime(
            timestamp.astimezone(tz_name),
            res_lang.date_format + ' ' + res_lang.time_format)
    return Datetime.context_timestamp(record, timestamp)