def make_salary_structure_for_timesheet(employee):
	salary_structure_name = "Timesheet Salary Structure Test"
	frequency = "Monthly"

	salary_structure = make_salary_structure(salary_structure_name, frequency, dont_submit=True)
	salary_structure.salary_component = "Timesheet Component"
	salary_structure.salary_slip_based_on_timesheet = 1
	salary_structure.hour_rate = 50.0
	salary_structure.save()
	salary_structure.submit()

	if not frappe.db.get_value("Salary Structure Assignment",
		{'employee':employee, 'docstatus': 1}):
			create_salary_structure_assignment(employee, salary_structure.name)

	return salary_structure
Beispiel #2
0
def make_salary_structure_for_timesheet(employee):
    salary_structure_name = "Timesheet Salary Structure Test"
    frequency = "Monthly"

    salary_structure = make_salary_structure(salary_structure_name,
                                             frequency,
                                             dont_submit=True)
    salary_structure.salary_component = "Timesheet Component"
    salary_structure.salary_slip_based_on_timesheet = 1
    salary_structure.hour_rate = 50.0
    salary_structure.save()
    salary_structure.submit()

    if not frappe.db.get_value("Salary Structure Assignment", {
            'employee': employee,
            'docstatus': 1
    }):
        create_salary_structure_assignment(employee, salary_structure.name)

    return salary_structure
    def test_tax_for_payroll_period(self):
        data = {}
        # test the impact of tax exemption declaration, tax exemption proof submission
        # and deduct check boxes in annual tax calculation
        # as per assigned salary structure 40500 in monthly salary so 236000*5/100/12
        frappe.db.sql("""delete from `tabPayroll Period`""")
        frappe.db.sql("""delete from `tabSalary Component`""")
        payroll_period = create_payroll_period()
        create_tax_slab(payroll_period)
        employee = make_employee("*****@*****.**")
        delete_docs = [
            "Salary Slip", "Additional Salary",
            "Employee Tax Exemption Declaration",
            "Employee Tax Exemption Proof Submission",
            "Employee Benefit Claim", "Salary Structure Assignment"
        ]
        for doc in delete_docs:
            frappe.db.sql("delete from `tab%s` where employee='%s'" %
                          (doc, employee))

        from erpnext.hr.doctype.salary_structure.test_salary_structure import \
         make_salary_structure, create_salary_structure_assignment
        salary_structure = make_salary_structure(
            "Stucture to test tax",
            "Monthly",
            other_details={"max_benefits": 100000},
            test_tax=True)
        create_salary_structure_assignment(employee, salary_structure.name,
                                           payroll_period.start_date)

        # create salary slip for whole period deducting tax only on last period
        # to find the total tax amount paid
        create_salary_slips_for_payroll_period(employee,
                                               salary_structure.name,
                                               payroll_period,
                                               deduct_random=False)
        tax_paid = get_tax_paid_in_period(employee)

        # total taxable income 586000, 250000 @ 5%, 86000 @ 20% ie. 12500 + 17200
        annual_tax = 113567.79
        try:
            self.assertEqual(tax_paid, annual_tax)
        except AssertionError:
            print("\nSalary Slip - Annual tax calculation failed\n")
            raise
        frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""",
                      (employee))

        # create exemption declaration so the tax amount varies
        create_exemption_declaration(employee, payroll_period.name)

        # create for payroll deducting in random months
        data["deducted_dates"] = create_salary_slips_for_payroll_period(
            employee, salary_structure.name, payroll_period)
        tax_paid = get_tax_paid_in_period(employee)

        # No proof, benefit claim sumitted, total tax paid, should not change
        try:
            self.assertEqual(tax_paid, annual_tax)
        except AssertionError:
            print("\nSalary Slip - Tax calculation failed on following case\n",
                  data, "\n")
            raise

        # Submit proof for total 120000
        data["proof-1"] = create_proof_submission(employee, payroll_period,
                                                  50000)
        data["proof-2"] = create_proof_submission(employee, payroll_period,
                                                  70000)

        # Submit benefit claim for total 50000
        data["benefit-1"] = create_benefit_claim(employee, payroll_period,
                                                 15000, "Medical Allowance")
        data["benefit-2"] = create_benefit_claim(employee, payroll_period,
                                                 35000,
                                                 "Leave Travel Allowance")

        frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""",
                      (employee))
        data["deducted_dates"] = create_salary_slips_for_payroll_period(
            employee, salary_structure.name, payroll_period)
        tax_paid = get_tax_paid_in_period(employee)

        # total taxable income 416000, 166000 @ 5% ie. 8300
        try:
            self.assertEqual(tax_paid, 88607.79)
        except AssertionError:
            print("\nSalary Slip - Tax calculation failed on following case\n",
                  data, "\n")
            raise

        # create additional salary of 150000
        frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""",
                      (employee))
        data["additional-1"] = create_additional_salary(
            employee, payroll_period, 50000)
        data["additional-2"] = create_additional_salary(
            employee, payroll_period, 100000)
        data["deducted_dates"] = create_salary_slips_for_payroll_period(
            employee, salary_structure.name, payroll_period)

        # total taxable income 566000, 250000 @ 5%, 66000 @ 20%, 12500 + 13200
        tax_paid = get_tax_paid_in_period(employee)
        try:
            self.assertEqual(tax_paid, 121211.48)
        except AssertionError:
            print("\nSalary Slip - Tax calculation failed on following case\n",
                  data, "\n")
            raise
        frappe.db.sql(
            """delete from `tabAdditional Salary` where employee=%s""",
            (employee))

        # undelete fixture data
        frappe.db.rollback()
	def test_tax_for_payroll_period(self):
		data = {}
		# test the impact of tax exemption declaration, tax exemption proof submission
		# and deduct check boxes in annual tax calculation
		# as per assigned salary structure 40500 in monthly salary so 236000*5/100/12
		frappe.db.sql("""delete from `tabPayroll Period`""")
		frappe.db.sql("""delete from `tabSalary Component`""")
		payroll_period = create_payroll_period()
		create_tax_slab(payroll_period)
		employee = make_employee("*****@*****.**")
		delete_docs = [
			"Salary Slip",
			"Additional Salary",
			"Employee Tax Exemption Declaration",
			"Employee Tax Exemption Proof Submission",
			"Employee Benefit Claim",
			"Salary Structure Assignment"
		]
		for doc in delete_docs:
			frappe.db.sql("delete from `tab%s` where employee='%s'" % (doc, employee))

		from erpnext.hr.doctype.salary_structure.test_salary_structure import \
			make_salary_structure, create_salary_structure_assignment
		salary_structure = make_salary_structure("Stucture to test tax", "Monthly",
			other_details={"max_benefits": 100000}, test_tax=True)
		create_salary_structure_assignment(employee, salary_structure.name,
			payroll_period.start_date)

		# create salary slip for whole period deducting tax only on last period
		# to find the total tax amount paid
		create_salary_slips_for_payroll_period(employee, salary_structure.name,
			payroll_period, deduct_random=False)
		tax_paid = get_tax_paid_in_period(employee)

		# total taxable income 586000, 250000 @ 5%, 86000 @ 20% ie. 12500 + 17200
		annual_tax = 29700
		try:
			self.assertEqual(tax_paid, annual_tax)
		except AssertionError:
			print("\nSalary Slip - Annual tax calculation failed\n")
			raise
		frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee))

		# create exemption declaration so the tax amount varies
		create_exemption_declaration(employee, payroll_period.name)

		# create for payroll deducting in random months
		data["deducted_dates"] = create_salary_slips_for_payroll_period(employee,
			salary_structure.name, payroll_period)
		tax_paid = get_tax_paid_in_period(employee)

		# No proof, benefit claim sumitted, total tax paid, should not change
		try:
			self.assertEqual(tax_paid, annual_tax)
		except AssertionError:
			print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n")
			raise

		# Submit proof for total 120000
		data["proof-1"] = create_proof_submission(employee, payroll_period, 50000)
		data["proof-2"] = create_proof_submission(employee, payroll_period, 70000)

		# Submit benefit claim for total 50000
		data["benefit-1"] = create_benefit_claim(employee, payroll_period, 15000, "Medical Allowance")
		data["benefit-2"] = create_benefit_claim(employee, payroll_period, 35000, "Leave Travel Allowance")


		frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee))
		data["deducted_dates"] = create_salary_slips_for_payroll_period(employee,
			salary_structure.name, payroll_period)
		tax_paid = get_tax_paid_in_period(employee)

		# total taxable income 416000, 166000 @ 5% ie. 8300
		try:
			self.assertEqual(tax_paid, 8300)
		except AssertionError:
			print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n")
			raise

		# create additional salary of 150000
		frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee))
		data["additional-1"] = create_additional_salary(employee, payroll_period, 50000)
		data["additional-2"] = create_additional_salary(employee, payroll_period, 100000)
		data["deducted_dates"] = create_salary_slips_for_payroll_period(employee,
			salary_structure.name, payroll_period)

		# total taxable income 566000, 250000 @ 5%, 66000 @ 20%, 12500 + 13200
		tax_paid = get_tax_paid_in_period(employee)
		try:
			self.assertEqual(tax_paid, 25700)
		except AssertionError:
			print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n")
			raise
		frappe.db.sql("""delete from `tabAdditional Salary` where employee=%s""", (employee))

		# undelete fixture data
		frappe.db.rollback()