コード例 #1
0
	def test_earned_leaves_creation(self):

		frappe.db.sql('''delete from `tabLeave Period`''')
		frappe.db.sql('''delete from `tabLeave Policy Assignment`''')
		frappe.db.sql('''delete from `tabLeave Allocation`''')
		frappe.db.sql('''delete from `tabLeave Ledger Entry`''')

		leave_period = get_leave_period()
		employee = get_employee()
		leave_type = 'Test Earned Leave Type'
		frappe.delete_doc_if_exists("Leave Type", 'Test Earned Leave Type', force=1)
		frappe.get_doc(dict(
			leave_type_name = leave_type,
			doctype = 'Leave Type',
			is_earned_leave = 1,
			earned_leave_frequency = 'Monthly',
			rounding = 0.5,
			max_leaves_allowed = 6
		)).insert()

		leave_policy = frappe.get_doc({
			"doctype": "Leave Policy",
			"leave_policy_details": [{"leave_type": leave_type, "annual_allocation": 6}]
		}).insert()

		data = {
			"assignment_based_on": "Leave Period",
			"leave_policy": leave_policy.name,
			"leave_period": leave_period.name
		}

		leave_policy_assignments = create_assignment_for_multiple_employees([employee.name], frappe._dict(data))

		frappe.get_doc("Leave Policy Assignment", leave_policy_assignments[0]).grant_leave_alloc_for_employee()

		from erpbee.hr.utils import allocate_earned_leaves
		i = 0
		while(i<14):
			allocate_earned_leaves()
			i += 1
		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 6)

		# validate earned leaves creation without maximum leaves
		frappe.db.set_value('Leave Type', leave_type, 'max_leaves_allowed', 0)
		i = 0
		while(i<6):
			allocate_earned_leaves()
			i += 1
		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 9)
コード例 #2
0
def make_leave_application():
    allocated_leaves = frappe.get_all("Leave Allocation",
                                      fields=['employee', 'leave_type'])

    for allocated_leave in allocated_leaves:
        leave_balance = get_leave_balance_on(
            allocated_leave.employee,
            allocated_leave.leave_type,
            frappe.flags.current_date,
            consider_all_leaves_in_the_allocation_period=True)
        if leave_balance != 0:
            if leave_balance == 1:
                to_date = frappe.flags.current_date
            else:
                to_date = add_days(frappe.flags.current_date,
                                   random.randint(0, leave_balance - 1))

            leave_application = frappe.get_doc({
                "doctype":
                "Leave Application",
                "employee":
                allocated_leave.employee,
                "from_date":
                frappe.flags.current_date,
                "to_date":
                to_date,
                "leave_type":
                allocated_leave.leave_type,
            })
            try:
                leave_application.insert()
                leave_application.submit()
                frappe.db.commit()
            except (OverlapError, AttendanceAlreadyMarkedError):
                frappe.db.rollback()
コード例 #3
0
    def test_leave_balance_on_submit(self):
        ''' check creation of leave allocation on submission of compensatory leave request '''
        employee = get_employee()
        mark_attendance(employee)
        compensatory_leave_request = get_compensatory_leave_request(
            employee.name)

        before = get_leave_balance_on(employee.name,
                                      compensatory_leave_request.leave_type,
                                      today())
        compensatory_leave_request.submit()

        self.assertEqual(
            get_leave_balance_on(employee.name,
                                 compensatory_leave_request.leave_type,
                                 add_days(today(), 1)), before + 1)
コード例 #4
0
	def test_leave_balance_near_allocaton_expiry(self):
		employee = get_employee()
		leave_type = create_leave_type(
			leave_type_name="_Test_CF_leave_expiry",
			is_carry_forward=1,
			expire_carry_forwarded_leaves_after_days=90)
		leave_type.submit()

		create_carry_forwarded_allocation(employee, leave_type)

		self.assertEqual(get_leave_balance_on(employee.name, leave_type.name, nowdate(), add_days(nowdate(), 8)), 21)
コード例 #5
0
	def test_leave_application_creation_after_expiry(self):
		# test leave balance for carry forwarded allocation
		employee = get_employee()
		leave_type = create_leave_type(
			leave_type_name="_Test_CF_leave_expiry",
			is_carry_forward=1,
			expire_carry_forwarded_leaves_after_days=90)
		leave_type.submit()

		create_carry_forwarded_allocation(employee, leave_type)

		self.assertEquals(get_leave_balance_on(employee.name, leave_type.name, add_days(nowdate(), -85), add_days(nowdate(), -84)), 0)
コード例 #6
0
	def test_optional_leave(self):
		leave_period = get_leave_period()
		today = nowdate()
		from datetime import date
		holiday_list = 'Test Holiday List for Optional Holiday'
		if not frappe.db.exists('Holiday List', holiday_list):
			frappe.get_doc(dict(
				doctype = 'Holiday List',
				holiday_list_name = holiday_list,
				from_date = add_months(today, -6),
				to_date = add_months(today, 6),
				holidays = [
					dict(holiday_date = today, description = 'Test')
				]
			)).insert()
		employee = get_employee()

		frappe.db.set_value('Leave Period', leave_period.name, 'optional_holiday_list', holiday_list)
		leave_type = 'Test Optional Type'
		if not frappe.db.exists('Leave Type', leave_type):
			frappe.get_doc(dict(
				leave_type_name = leave_type,
				doctype = 'Leave Type',
				is_optional_leave = 1
			)).insert()

		allocate_leaves(employee, leave_period, leave_type, 10)

		date = add_days(today, - 1)

		leave_application = frappe.get_doc(dict(
			doctype = 'Leave Application',
			employee = employee.name,
			company = '_Test Company',
			description = "_Test Reason",
			leave_type = leave_type,
			from_date = date,
			to_date = date,
		))

		# can only apply on optional holidays
		self.assertRaises(NotAnOptionalHoliday, leave_application.insert)

		leave_application.from_date = today
		leave_application.to_date = today
		leave_application.status = "Approved"
		leave_application.insert()
		leave_application.submit()

		# check leave balance is reduced
		self.assertEqual(get_leave_balance_on(employee.name, leave_type, today), 9)
コード例 #7
0
def get_data(filters):
    leave_types = frappe.db.sql_list(
        "SELECT `name` FROM `tabLeave Type` ORDER BY `name` ASC")

    conditions = get_conditions(filters)

    user = frappe.session.user
    department_approver_map = get_department_leave_approver_map(
        filters.get('department'))

    active_employees = frappe.get_list('Employee',
                                       filters=conditions,
                                       fields=[
                                           'name', 'employee_name',
                                           'department', 'user_id',
                                           'leave_approver'
                                       ])

    data = []

    for leave_type in leave_types:
        if len(active_employees) > 1:
            data.append({'leave_type': leave_type})
        else:
            row = frappe._dict({'leave_type': leave_type})

        for employee in active_employees:

            leave_approvers = department_approver_map.get(
                employee.department_name, []).append(employee.leave_approver)

            if (leave_approvers and len(leave_approvers) and user in leave_approvers) or (user in ["Administrator", employee.user_id]) \
             or ("HR Manager" in frappe.get_roles(user)):
                if len(active_employees) > 1:
                    row = frappe._dict()
                row.employee = employee.name,
                row.employee_name = employee.employee_name

                leaves_taken = get_leaves_for_period(employee.name, leave_type,
                                                     filters.from_date,
                                                     filters.to_date) * -1

                new_allocation, expired_leaves = get_allocated_and_expired_leaves(
                    filters.from_date, filters.to_date, employee.name,
                    leave_type)

                opening = get_leave_balance_on(
                    employee.name, leave_type,
                    add_days(filters.from_date,
                             -1))  #allocation boundary condition

                row.leaves_allocated = new_allocation
                row.leaves_expired = expired_leaves - leaves_taken if expired_leaves - leaves_taken > 0 else 0
                row.opening_balance = opening
                row.leaves_taken = leaves_taken

                # not be shown on the basis of days left it create in user mind for carry_forward leave
                row.closing_balance = (new_allocation + opening -
                                       (row.leaves_expired + leaves_taken))

                row.indent = 1
                data.append(row)
                new_leaves_allocated = 0

    return data