示例#1
0
	def test_year_to_date_computation(self):
		from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure

		applicant = make_employee("*****@*****.**", company="_Test Company")

		payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company")

		create_tax_slab(payroll_period, allow_tax_exemption=True, currency="INR", effective_date=getdate("2019-04-01"),
			company="_Test Company")

		salary_structure = make_salary_structure("Monthly Salary Structure Test for Salary Slip YTD",
			"Monthly", employee=applicant, company="_Test Company", currency="INR", payroll_period=payroll_period)

		# clear salary slip for this employee
		frappe.db.sql("DELETE FROM `tabSalary Slip` where employee_name = '*****@*****.**'")

		create_salary_slips_for_payroll_period(applicant, salary_structure.name,
			payroll_period, deduct_random=False)

		salary_slips = frappe.get_all('Salary Slip', fields=['year_to_date', 'net_pay'], filters={'employee_name':
			'*****@*****.**'}, order_by = 'posting_date')

		year_to_date = 0
		for slip in salary_slips:
			year_to_date += flt(slip.net_pay)
			self.assertEqual(slip.year_to_date, year_to_date)
def create_salary_structure_assignment(
    employee,
    salary_structure,
    from_date=None,
    company=None,
    currency=erpnext.get_default_currency()):
    if frappe.db.exists("Salary Structure Assignment", {"employee": employee}):
        frappe.db.sql(
            """delete from `tabSalary Structure Assignment` where employee=%s""",
            (employee))

    payroll_period = create_payroll_period()
    create_tax_slab(payroll_period,
                    allow_tax_exemption=True,
                    currency=currency)

    salary_structure_assignment = frappe.new_doc("Salary Structure Assignment")
    salary_structure_assignment.employee = employee
    salary_structure_assignment.base = 50000
    salary_structure_assignment.variable = 5000
    salary_structure_assignment.from_date = from_date or add_days(
        nowdate(), -1)
    salary_structure_assignment.salary_structure = salary_structure
    salary_structure_assignment.currency = currency
    salary_structure_assignment.payroll_payable_account = get_payable_account(
        company)
    salary_structure_assignment.company = company or erpnext.get_default_company(
    )
    salary_structure_assignment.save(ignore_permissions=True)
    salary_structure_assignment.income_tax_slab = "Tax Slab: _Test Payroll Period"
    salary_structure_assignment.submit()
    return salary_structure_assignment
示例#3
0
	def test_component_wise_year_to_date_computation(self):
		from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure

		applicant = make_employee("*****@*****.**", company="_Test Company")

		payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company")

		create_tax_slab(payroll_period, allow_tax_exemption=True, currency="INR", effective_date=getdate("2019-04-01"),
			company="_Test Company")

		salary_structure = make_salary_structure("Monthly Salary Structure Test for Salary Slip YTD",
			"Monthly", employee=applicant, company="_Test Company", currency="INR", payroll_period=payroll_period)

		# clear salary slip for this employee
		frappe.db.sql("DELETE FROM `tabSalary Slip` where employee_name = '*****@*****.**'")

		create_salary_slips_for_payroll_period(applicant, salary_structure.name,
			payroll_period, deduct_random=False, num=3)

		salary_slips = frappe.get_all("Salary Slip", fields=["name"], filters={"employee_name":
			"*****@*****.**"}, order_by = "posting_date")

		year_to_date = dict()
		for slip in salary_slips:
			doc = frappe.get_doc("Salary Slip", slip.name)
			for entry in doc.get("earnings"):
				if not year_to_date.get(entry.salary_component):
					year_to_date[entry.salary_component] = 0

				year_to_date[entry.salary_component] += entry.amount
				self.assertEqual(year_to_date[entry.salary_component], entry.year_to_date)
示例#4
0
    def create_records(self):
        self.employee = make_employee(
            "*****@*****.**",
            company="_Test Company",
            date_of_joining=getdate("01-10-2021"),
        )

        self.payroll_period = create_payroll_period(
            name="_Test Payroll Period 1", company="_Test Company")

        self.income_tax_slab = create_tax_slab(
            self.payroll_period,
            allow_tax_exemption=True,
            effective_date=getdate("2019-04-01"),
            company="_Test Company",
        )
        salary_structure = make_salary_structure(
            "Monthly Salary Structure Test Income Tax Computation",
            "Monthly",
            employee=self.employee,
            company="_Test Company",
            currency="INR",
            payroll_period=self.payroll_period,
            test_tax=True,
        )

        create_exemption_declaration(self.employee, self.payroll_period.name)

        create_salary_slips_for_payroll_period(self.employee,
                                               salary_structure.name,
                                               self.payroll_period,
                                               deduct_random=False,
                                               num=3)
def create_salary_structure_assignment(employee, salary_structure, from_date=None, company=None, currency=erpnext.get_default_currency(),
	payroll_period=None):

	if frappe.db.exists("Salary Structure Assignment", {"employee": employee}):
		frappe.db.sql("""delete from `tabSalary Structure Assignment` where employee=%s""",(employee))

	if not payroll_period:
		payroll_period = create_payroll_period()

	income_tax_slab = frappe.db.get_value("Income Tax Slab", {"currency": currency})

	if not income_tax_slab:
		income_tax_slab = create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency)

	salary_structure_assignment = frappe.new_doc("Salary Structure Assignment")
	salary_structure_assignment.employee = employee
	salary_structure_assignment.base = 50000
	salary_structure_assignment.variable = 5000

	if getdate(nowdate()).day == 1:
		date = from_date or nowdate()
	else:
		date = from_date or add_days(nowdate(), -1)

	salary_structure_assignment.from_date = date
	salary_structure_assignment.salary_structure = salary_structure
	salary_structure_assignment.currency = currency
	salary_structure_assignment.payroll_payable_account = get_payable_account(company)
	salary_structure_assignment.company = company or erpnext.get_default_company()
	salary_structure_assignment.save(ignore_permissions=True)
	salary_structure_assignment.income_tax_slab = income_tax_slab
	salary_structure_assignment.submit()
	return salary_structure_assignment
    def test_loan_repayment_salary_slip(self):
        from erpnext.loan_management.doctype.loan.test_loan import create_loan_type, create_loan, make_loan_disbursement_entry, create_loan_accounts
        from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import process_loan_interest_accrual_for_term_loans
        from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure

        applicant = make_employee("*****@*****.**",
                                  company="_Test Company")

        create_loan_accounts()

        create_loan_type(
            "Car Loan",
            500000,
            8.4,
            is_term_loan=1,
            mode_of_payment='Cash',
            payment_account='Payment Account - _TC',
            loan_account='Loan Account - _TC',
            interest_income_account='Interest Income Account - _TC',
            penalty_income_account='Penalty Income Account - _TC')

        payroll_period = create_payroll_period(name="_Test Payroll Period 1",
                                               company="_Test Company")

        make_salary_structure("Test Loan Repayment Salary Structure",
                              "Monthly",
                              employee=applicant,
                              currency='INR',
                              payroll_period=payroll_period)

        frappe.db.sql("delete from tabLoan")
        loan = create_loan(applicant,
                           "Car Loan",
                           11000,
                           "Repay Over Number of Periods",
                           20,
                           posting_date=add_months(nowdate(), -1))
        loan.repay_from_salary = 1
        loan.submit()

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=add_months(
                                         nowdate(), -1))

        process_loan_interest_accrual_for_term_loans(posting_date=nowdate())

        ss = make_employee_salary_slip(
            "*****@*****.**", "Monthly",
            "Test Loan Repayment Salary Structure")
        ss.submit()

        self.assertEqual(ss.total_loan_repayment, 592)
        self.assertEqual(
            ss.net_pay,
            (flt(ss.gross_pay) -
             (flt(ss.total_deduction) + flt(ss.total_loan_repayment))))
示例#7
0
def create_salary_structure_assignment(
    employee,
    salary_structure,
    from_date=None,
    company=None,
    currency=erpnext.get_default_currency(),
    payroll_period=None,
    base=None,
    allow_duplicate=False,
):
    if not allow_duplicate and frappe.db.exists("Salary Structure Assignment",
                                                {"employee": employee}):
        frappe.db.sql(
            """delete from `tabSalary Structure Assignment` where employee=%s""",
            (employee))

    if not payroll_period:
        payroll_period = create_payroll_period()

    income_tax_slab = frappe.db.get_value("Income Tax Slab",
                                          {"currency": currency})

    if not income_tax_slab:
        income_tax_slab = create_tax_slab(payroll_period,
                                          allow_tax_exemption=True,
                                          currency=currency)

    salary_structure_assignment = frappe.new_doc("Salary Structure Assignment")
    salary_structure_assignment.employee = employee
    salary_structure_assignment.base = base or 50000
    salary_structure_assignment.variable = 5000

    if not from_date:
        from_date = get_first_day(nowdate())
        joining_date = frappe.get_cached_value("Employee", employee,
                                               "date_of_joining")
        if date_diff(joining_date, from_date) > 0:
            from_date = joining_date

    salary_structure_assignment.from_date = from_date
    salary_structure_assignment.salary_structure = salary_structure
    salary_structure_assignment.currency = currency
    salary_structure_assignment.payroll_payable_account = get_payable_account(
        company)
    salary_structure_assignment.company = company or erpnext.get_default_company(
    )
    salary_structure_assignment.save(ignore_permissions=True)
    salary_structure_assignment.income_tax_slab = income_tax_slab
    salary_structure_assignment.submit()
    return salary_structure_assignment
示例#8
0
	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`""")
		frappe.db.sql("""delete from `tabAdditional Salary`""")

		payroll_period = create_payroll_period()

		create_tax_slab(payroll_period, allow_tax_exemption=True)

		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.payroll.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)

		annual_tax = 113589.0
		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"] = create_proof_submission(employee, payroll_period, 120000)

		# 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, 82389.0)
		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, 150000)
		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, annual_tax)
		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 setup(self):
     make_employee("*****@*****.**")
     create_payroll_period()
     create_exemption_category()
     frappe.db.sql(
         """delete from `tabEmployee Tax Exemption Proof Submission`""")
示例#10
0
 def setUp(self):
     make_employee("*****@*****.**", company="_Test Company")
     create_payroll_period(company="_Test Company")
     create_exemption_category()
     frappe.db.delete("Employee Tax Exemption Proof Submission")
     frappe.db.delete("Salary Structure Assignment")