Пример #1
0
    def test_validation_for_over_allocation(self):
        leave_type = create_leave_type(leave_type_name="Test Over Allocation",
                                       is_carry_forward=1)
        leave_type.save()

        doc = frappe.get_doc({
            "doctype": "Leave Allocation",
            "__islocal": 1,
            "employee": self.employee.name,
            "employee_name": self.employee.employee_name,
            "leave_type": leave_type.name,
            "from_date": getdate("2015-09-1"),
            "to_date": getdate("2015-09-30"),
            "new_leaves_allocated": 35,
            "carry_forward": 1,
        })

        # allocated leave more than period
        self.assertRaises(OverAllocationError, doc.save)

        leave_type.allow_over_allocation = 1
        leave_type.save()

        # allows creating a leave allocation with more leave days than period days
        doc = frappe.get_doc({
            "doctype": "Leave Allocation",
            "__islocal": 1,
            "employee": self.employee.name,
            "employee_name": self.employee.employee_name,
            "leave_type": leave_type.name,
            "from_date": getdate("2015-09-1"),
            "to_date": getdate("2015-09-30"),
            "new_leaves_allocated": 35,
            "carry_forward": 1,
        }).insert()
Пример #2
0
	def test_creation_of_leave_ledger_entry_on_submit(self):
		employee = get_employee()

		leave_type = create_leave_type(leave_type_name = 'Test Leave Type 1')
		leave_type.save()

		leave_allocation = create_leave_allocation(employee=employee.name, employee_name=employee.employee_name,
			leave_type=leave_type.name)
		leave_allocation.submit()

		leave_application = frappe.get_doc(dict(
			doctype = 'Leave Application',
			employee = employee.name,
			leave_type = leave_type.name,
			from_date = add_days(nowdate(), 1),
			to_date = add_days(nowdate(), 4),
			description = "_Test Reason",
			company = "_Test Company",
			docstatus = 1,
            status = "Approved"
		))
		leave_application.submit()
		leave_ledger_entry = frappe.get_all('Leave Ledger Entry', fields='*', filters=dict(transaction_name=leave_application.name))

		self.assertEquals(leave_ledger_entry[0].employee, leave_application.employee)
		self.assertEquals(leave_ledger_entry[0].leave_type, leave_application.leave_type)
		self.assertEquals(leave_ledger_entry[0].leaves, leave_application.total_leave_days * -1)

		# check if leave ledger entry is deleted on cancellation
		leave_application.cancel()
		self.assertFalse(frappe.db.exists("Leave Ledger Entry", {'transaction_name':leave_application.name}))
Пример #3
0
	def test_ledger_entry_creation_on_intermediate_allocation_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)

		leave_application = frappe.get_doc(dict(
			doctype = 'Leave Application',
			employee = employee.name,
			leave_type = leave_type.name,
			from_date = add_days(nowdate(), -3),
			to_date = add_days(nowdate(), 7),
			description = "_Test Reason",
			company = "_Test Company",
			docstatus = 1,
            status = "Approved"
		))
		leave_application.submit()

		leave_ledger_entry = frappe.get_all('Leave Ledger Entry', '*', filters=dict(transaction_name=leave_application.name))

		self.assertEquals(len(leave_ledger_entry), 2)
		self.assertEquals(leave_ledger_entry[0].employee, leave_application.employee)
		self.assertEquals(leave_ledger_entry[0].leave_type, leave_application.leave_type)
		self.assertEquals(leave_ledger_entry[0].leaves, -9)
		self.assertEquals(leave_ledger_entry[1].leaves, -2)
Пример #4
0
	def test_validate_back_dated_allocation_update(self):
		leave_type = create_leave_type(leave_type_name="_Test_CF_leave", is_carry_forward=1)
		leave_type.save()

		# initial leave allocation = 15
		leave_allocation = create_leave_allocation(
			employee=self.employee.name,
			employee_name=self.employee.employee_name,
			leave_type="_Test_CF_leave",
			from_date=add_months(nowdate(), -12),
			to_date=add_months(nowdate(), -1),
			carry_forward=0,
		)
		leave_allocation.submit()

		# new_leaves = 15, carry_forwarded = 10
		leave_allocation_1 = create_leave_allocation(
			employee=self.employee.name,
			employee_name=self.employee.employee_name,
			leave_type="_Test_CF_leave",
			carry_forward=1,
		)
		leave_allocation_1.submit()

		# try updating initial leave allocation
		leave_allocation.reload()
		leave_allocation.new_leaves_allocated = 20
		self.assertRaises(BackDatedAllocationError, leave_allocation.save)
Пример #5
0
    def test_payment_days_based_on_leave_application(self):
        no_of_days = self.get_no_of_days()

        # Payroll based on attendance
        frappe.db.set_value("Payroll Settings", None,
                            "payroll_based_on", "Leave")

        emp_id = make_employee(
            "*****@*****.**")
        frappe.db.set_value("Employee", emp_id, {
                            "relieving_date": None, "status": "Active"})

        frappe.db.set_value(
            "Leave Type", "Leave Without Pay", "include_holiday", 0)

        month_start_date = get_first_day(nowdate())
        month_end_date = get_last_day(nowdate())

        first_sunday = frappe.db.sql("""
			select holiday_date from `tabHoliday`
			where parent = 'Salary Slip Test Holiday List'
				and holiday_date between %s and %s
			order by holiday_date
		""", (month_start_date, month_end_date))[0][0]

        make_leave_application(emp_id, first_sunday, add_days(
            first_sunday, 3), "Leave Without Pay")

        leave_type_ppl = create_leave_type(
            leave_type_name="Test Partially Paid Leave", is_ppl=1)
        leave_type_ppl.save()

        alloc = create_leave_allocation(
            employee=emp_id, from_date=add_days(first_sunday, 4),
            to_date=add_days(first_sunday, 10), new_leaves_allocated=3,
            leave_type="Test Partially Paid Leave")
        alloc.save()
        alloc.submit()

        # two day leave ppl with fraction_of_daily_salary_per_leave = 0.5 equivalent to single day lwp
        make_leave_application(emp_id, add_days(first_sunday, 4), add_days(
            first_sunday, 5), "Test Partially Paid Leave")

        ss = make_employee_salary_slip(
            "*****@*****.**", "Monthly", "Test Payment Based On Leave Application")

        self.assertEqual(ss.leave_without_pay, 4)

        days_in_month = no_of_days[0]
        no_of_holidays = no_of_days[1]

        self.assertEqual(ss.payment_days, days_in_month - no_of_holidays - 4)

        frappe.db.set_value("Payroll Settings", None,
                            "payroll_based_on", "Leave")
Пример #6
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)
Пример #7
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)
Пример #8
0
    def test_opening_balance_considers_carry_forwarded_leaves(self):
        leave_type = create_leave_type(leave_type_name="_Test_CF_leave_expiry",
                                       is_carry_forward=1)
        leave_type.insert()

        # 30 leaves allocated for first half of the year
        allocation1 = make_allocation_record(
            employee=self.employee_id,
            from_date=self.year_start,
            to_date=self.mid_year,
            leave_type=leave_type.name,
        )
        # 4 days leave application in the first allocation
        first_sunday = get_first_sunday(self.holiday_list,
                                        for_date=self.year_start)
        leave_application = make_leave_application(self.employee_id,
                                                   first_sunday,
                                                   add_days(first_sunday, 3),
                                                   leave_type.name)
        leave_application.reload()
        # 30 leaves allocated for second half of the year + carry forward leaves (26) from the previous allocation
        allocation2 = make_allocation_record(
            employee=self.employee_id,
            from_date=add_days(self.mid_year, 1),
            to_date=self.year_end,
            carry_forward=True,
            leave_type=leave_type.name,
        )

        # Case 1: carry forwarded leaves considered in opening balance for second alloc
        filters = frappe._dict({
            "from_date": add_days(self.mid_year, 1),
            "to_date": self.year_end,
            "employee": self.employee_id,
        })
        report = execute(filters)
        # available leaves from old alloc
        opening_balance = allocation1.new_leaves_allocated - leave_application.total_leave_days
        self.assertEqual(report[1][0].opening_balance, opening_balance)

        # Case 2: opening balance one day after alloc boundary = carry forwarded leaves + new leaves alloc
        filters = frappe._dict({
            "from_date": add_days(self.mid_year, 2),
            "to_date": self.year_end,
            "employee": self.employee_id,
        })
        report = execute(filters)
        # available leaves from old alloc
        opening_balance = allocation2.new_leaves_allocated + (
            allocation1.new_leaves_allocated -
            leave_application.total_leave_days)
        self.assertEqual(report[1][0].opening_balance, opening_balance)
Пример #9
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.insert()

		create_carry_forwarded_allocation(employee, leave_type)
		details = get_leave_balance_on(
			employee.name, leave_type.name, nowdate(), add_days(nowdate(), 8), for_consumption=True
		)

		self.assertEqual(details.leave_balance_for_consumption, 21)
		self.assertEqual(details.leave_balance, 30)
Пример #10
0
    def test_carry_forward_calculation(self):
        leave_type = create_leave_type(leave_type_name="_Test_CF_leave",
                                       is_carry_forward=1)
        leave_type.maximum_carry_forwarded_leaves = 10
        leave_type.max_leaves_allowed = 30
        leave_type.save()

        # initial leave allocation = 15
        leave_allocation = create_leave_allocation(
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            leave_type="_Test_CF_leave",
            from_date=add_months(nowdate(), -12),
            to_date=add_months(nowdate(), -1),
            carry_forward=0,
        )
        leave_allocation.submit()

        # carry forwarded leaves considering maximum_carry_forwarded_leaves
        # new_leaves = 15, carry_forwarded = 10
        leave_allocation_1 = create_leave_allocation(
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            leave_type="_Test_CF_leave",
            carry_forward=1,
        )
        leave_allocation_1.submit()
        leave_allocation_1.reload()

        self.assertEqual(leave_allocation_1.unused_leaves, 10)
        self.assertEqual(leave_allocation_1.total_leaves_allocated, 25)

        leave_allocation_1.cancel()

        # carry forwarded leaves considering max_leave_allowed
        # max_leave_allowed = 30, new_leaves = 25, carry_forwarded = 5
        leave_allocation_2 = create_leave_allocation(
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            leave_type="_Test_CF_leave",
            carry_forward=1,
            new_leaves_allocated=25,
        )
        leave_allocation_2.submit()

        self.assertEqual(leave_allocation_2.unused_leaves, 5)
Пример #11
0
    def test_carry_forward_leaves_expiry(self):
        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.save()

        # initial leave allocation
        leave_allocation = create_leave_allocation(
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            leave_type="_Test_CF_leave_expiry",
            from_date=add_months(nowdate(), -24),
            to_date=add_months(nowdate(), -12),
            carry_forward=0,
        )
        leave_allocation.submit()

        leave_allocation = create_leave_allocation(
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            leave_type="_Test_CF_leave_expiry",
            from_date=add_days(nowdate(), -90),
            to_date=add_days(nowdate(), 100),
            carry_forward=1,
        )
        leave_allocation.submit()

        # expires all the carry forwarded leaves after 90 days
        process_expired_allocation()

        # leave allocation with carry forward of only new leaves allocated
        leave_allocation_1 = create_leave_allocation(
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            leave_type="_Test_CF_leave_expiry",
            carry_forward=1,
            from_date=add_months(nowdate(), 6),
            to_date=add_months(nowdate(), 12),
        )
        leave_allocation_1.submit()

        self.assertEqual(leave_allocation_1.unused_leaves,
                         leave_allocation.new_leaves_allocated)
Пример #12
0
    def test_validation_for_over_allocation_based_on_leave_setup_post_submission(
            self):
        frappe.delete_doc_if_exists("Leave Period", "Test Allocation Period")
        leave_period = frappe.get_doc(
            dict(
                name="Test Allocation Period",
                doctype="Leave Period",
                from_date=add_months(nowdate(), -6),
                to_date=add_months(nowdate(), 6),
                company="_Test Company",
                is_active=1,
            )).insert()

        leave_type = create_leave_type(
            leave_type_name="_Test Allocation Validation", is_carry_forward=1)
        leave_type.max_leaves_allowed = 30
        leave_type.save()

        # 15 leaves allocated
        allocation = create_leave_allocation(
            leave_type=leave_type.name,
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            from_date=leave_period.from_date,
            to_date=nowdate(),
        )
        allocation.submit()
        allocation.reload()

        # allocate additional 15 leaves
        allocation = create_leave_allocation(
            leave_type=leave_type.name,
            employee=self.employee.name,
            employee_name=self.employee.employee_name,
            from_date=add_days(nowdate(), 1),
            to_date=leave_period.to_date,
        )
        allocation.submit()
        allocation.reload()

        # trying to allocate 25 leaves in 2nd alloc within leave period
        # total leaves = 40 which is more than `max_leaves_allowed` setting i.e. 30
        allocation.new_leaves_allocated = 25
        self.assertRaises(OverAllocationError, allocation.save)
Пример #13
0
	def test_get_leave_allocation_records(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.insert()

		leave_alloc = create_carry_forwarded_allocation(employee, leave_type)
		details = get_leave_allocation_records(employee.name, getdate(), leave_type.name)
		expected_data = {
			"from_date": getdate(leave_alloc.from_date),
			"to_date": getdate(leave_alloc.to_date),
			"total_leaves_allocated": 30.0,
			"unused_leaves": 15.0,
			"new_leaves_allocated": 15.0,
			"leave_type": leave_type.name,
		}
		self.assertEqual(details.get(leave_type.name), expected_data)
Пример #14
0
    def test_carry_forward_calculation(self):
        frappe.db.sql("delete from `tabLeave Allocation`")
        frappe.db.sql("delete from `tabLeave Ledger Entry`")
        leave_type = create_leave_type(leave_type_name="_Test_CF_leave",
                                       is_carry_forward=1)
        leave_type.submit()

        # initial leave allocation
        leave_allocation = create_leave_allocation(
            leave_type="_Test_CF_leave",
            from_date=add_months(nowdate(), -12),
            to_date=add_months(nowdate(), -1),
            carry_forward=0)
        leave_allocation.submit()

        # leave allocation with carry forward from previous allocation
        leave_allocation_1 = create_leave_allocation(
            leave_type="_Test_CF_leave", carry_forward=1)
        leave_allocation_1.submit()

        self.assertEquals(leave_allocation.total_leaves_allocated,
                          leave_allocation_1.unused_leaves)
Пример #15
0
    def test_carry_forward_leaves_expiry(self):
        frappe.db.sql("delete from `tabLeave Allocation`")
        frappe.db.sql("delete from `tabLeave Ledger Entry`")
        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.save()

        # initial leave allocation
        leave_allocation = create_leave_allocation(
            leave_type="_Test_CF_leave_expiry",
            from_date=add_months(nowdate(), -24),
            to_date=add_months(nowdate(), -12),
            carry_forward=0)
        leave_allocation.submit()

        leave_allocation = create_leave_allocation(
            leave_type="_Test_CF_leave_expiry",
            from_date=add_days(nowdate(), -90),
            to_date=add_days(nowdate(), 100),
            carry_forward=1)
        leave_allocation.submit()

        # expires all the carry forwarded leaves after 90 days
        process_expired_allocation()

        # leave allocation with carry forward of only new leaves allocated
        leave_allocation_1 = create_leave_allocation(
            leave_type="_Test_CF_leave_expiry",
            carry_forward=1,
            from_date=add_months(nowdate(), 6),
            to_date=add_months(nowdate(), 12))
        leave_allocation_1.submit()

        self.assertEquals(leave_allocation_1.unused_leaves,
                          leave_allocation.new_leaves_allocated)
Пример #16
0
    def test_carry_forward_calculation(self):
        frappe.db.sql("delete from `tabLeave Allocation`")
        frappe.db.sql("delete from `tabLeave Ledger Entry`")
        leave_type = create_leave_type(leave_type_name="_Test_CF_leave",
                                       is_carry_forward=1)
        leave_type.maximum_carry_forwarded_leaves = 10
        leave_type.max_leaves_allowed = 30
        leave_type.save()

        # initial leave allocation = 15
        leave_allocation = create_leave_allocation(
            leave_type="_Test_CF_leave",
            from_date=add_months(nowdate(), -12),
            to_date=add_months(nowdate(), -1),
            carry_forward=0)
        leave_allocation.submit()

        # carry forwarded leaves considering maximum_carry_forwarded_leaves
        # new_leaves = 15, carry_forwarded = 10
        leave_allocation_1 = create_leave_allocation(
            leave_type="_Test_CF_leave", carry_forward=1)
        leave_allocation_1.submit()

        self.assertEquals(leave_allocation_1.unused_leaves, 10)

        leave_allocation_1.cancel()

        # carry forwarded leaves considering max_leave_allowed
        # max_leave_allowed = 30, new_leaves = 25, carry_forwarded = 5
        leave_allocation_2 = create_leave_allocation(
            leave_type="_Test_CF_leave",
            carry_forward=1,
            new_leaves_allocated=25)
        leave_allocation_2.submit()

        self.assertEquals(leave_allocation_2.unused_leaves, 5)
Пример #17
0
	def test_validation_for_over_allocation_based_on_leave_setup(self):
		frappe.delete_doc_if_exists("Leave Period", "Test Allocation Period")
		leave_period = frappe.get_doc(
			dict(
				name="Test Allocation Period",
				doctype="Leave Period",
				from_date=add_months(nowdate(), -6),
				to_date=add_months(nowdate(), 6),
				company="_Test Company",
				is_active=1,
			)
		).insert()

		leave_type = create_leave_type(leave_type_name="_Test Allocation Validation", is_carry_forward=1)
		leave_type.max_leaves_allowed = 25
		leave_type.save()

		# 15 leaves allocated in this period
		allocation = create_leave_allocation(
			leave_type=leave_type.name,
			employee=self.employee.name,
			employee_name=self.employee.employee_name,
			from_date=leave_period.from_date,
			to_date=nowdate(),
		)
		allocation.submit()

		# trying to allocate additional 15 leaves
		allocation = create_leave_allocation(
			leave_type=leave_type.name,
			employee=self.employee.name,
			employee_name=self.employee.employee_name,
			from_date=add_days(nowdate(), 1),
			to_date=leave_period.to_date,
		)
		self.assertRaises(OverAllocationError, allocation.save)