70 lines
3.1 KiB
Python
70 lines
3.1 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||
|
|
||
|
import datetime
|
||
|
from freezegun import freeze_time
|
||
|
from dateutil.relativedelta import relativedelta
|
||
|
|
||
|
from odoo.tests import tagged
|
||
|
|
||
|
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon
|
||
|
|
||
|
|
||
|
@tagged('post_install', '-at_install', 'accruals')
|
||
|
class TestAccrualAllocationsAttendance(TestHrHolidaysCommon):
|
||
|
|
||
|
@classmethod
|
||
|
def setUpClass(cls):
|
||
|
super(TestAccrualAllocationsAttendance, cls).setUpClass()
|
||
|
cls.leave_type = cls.env['hr.leave.type'].create({
|
||
|
'name': 'Paid Time Off',
|
||
|
'time_type': 'leave',
|
||
|
'requires_allocation': 'yes',
|
||
|
'allocation_validation_type': 'officer',
|
||
|
})
|
||
|
|
||
|
def test_frequency_hourly_attendance(self):
|
||
|
with freeze_time("2017-12-5"):
|
||
|
accrual_plan = self.env['hr.leave.accrual.plan'].with_context(tracking_disable=True).create({
|
||
|
'name': 'Accrual Plan For Test',
|
||
|
'is_based_on_worked_time': True,
|
||
|
'level_ids': [(0, 0, {
|
||
|
'start_count': 1,
|
||
|
'start_type': 'day',
|
||
|
'added_value': 1,
|
||
|
'added_value_type': 'day',
|
||
|
'frequency': 'hourly',
|
||
|
'frequency_hourly_source': 'attendance',
|
||
|
'cap_accrued_time': True,
|
||
|
'maximum_leave': 10000
|
||
|
})],
|
||
|
})
|
||
|
allocation = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||
|
'name': 'Accrual allocation for employee',
|
||
|
'accrual_plan_id': accrual_plan.id,
|
||
|
'employee_id': self.employee_emp.id,
|
||
|
'holiday_status_id': self.leave_type.id,
|
||
|
'number_of_days': 0,
|
||
|
'allocation_type': 'accrual',
|
||
|
})
|
||
|
allocation.action_validate()
|
||
|
self.assertFalse(allocation.nextcall, 'There should be no nextcall set on the allocation.')
|
||
|
self.assertEqual(allocation.number_of_days, 0, 'There should be no days allocated yet.')
|
||
|
allocation._update_accrual()
|
||
|
tomorrow = datetime.date.today() + relativedelta(days=2)
|
||
|
self.assertEqual(allocation.number_of_days, 0, 'There should be no days allocated yet. The accrual starts tomorrow.')
|
||
|
|
||
|
self.env['hr.attendance'].create({
|
||
|
'employee_id': self.employee_emp.id,
|
||
|
'check_in': datetime.datetime(2017, 12, 6, 8, 0, 0),
|
||
|
'check_out': datetime.datetime(2017, 12, 6, 13, 22, 0),
|
||
|
})
|
||
|
|
||
|
with freeze_time(tomorrow):
|
||
|
allocation._update_accrual()
|
||
|
nextcall = datetime.date.today() + relativedelta(days=1)
|
||
|
self.assertAlmostEqual(allocation.number_of_days, 4.37, places=2)
|
||
|
self.assertEqual(allocation.nextcall, nextcall, 'The next call date of the cron should be in 2 days.')
|
||
|
allocation._update_accrual()
|
||
|
self.assertAlmostEqual(allocation.number_of_days, 4.37, places=2)
|