From b81d7519c1c5c0d24e42a26c9175ac6e14511133 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 27 May 2022 12:58:10 +0530 Subject: [PATCH] test: Gratuity status for payment via salary slip --- .../payroll/doctype/gratuity/test_gratuity.py | 23 ++++++++++++++++--- .../doctype/salary_slip/test_salary_slip.py | 10 +++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/erpnext/payroll/doctype/gratuity/test_gratuity.py b/erpnext/payroll/doctype/gratuity/test_gratuity.py index aa03d80d63..5955758a30 100644 --- a/erpnext/payroll/doctype/gratuity/test_gratuity.py +++ b/erpnext/payroll/doctype/gratuity/test_gratuity.py @@ -4,7 +4,8 @@ import unittest import frappe -from frappe.utils import add_days, flt, get_datetime, getdate +from frappe.tests.utils import FrappeTestCase +from frappe.utils import add_days, add_months, flt, get_datetime, get_first_day, getdate from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.expense_claim.test_expense_claim import get_payable_account @@ -14,14 +15,16 @@ from erpnext.payroll.doctype.salary_slip.test_salary_slip import ( make_earning_salary_component, make_employee_salary_slip, ) +from erpnext.payroll.doctype.salary_structure.salary_structure import make_salary_slip from erpnext.regional.united_arab_emirates.setup import create_gratuity_rule test_dependencies = ["Salary Component", "Salary Slip", "Account"] -class TestGratuity(unittest.TestCase): +class TestGratuity(FrappeTestCase): def setUp(self): frappe.db.delete("Gratuity") + frappe.db.delete("Salary Slip") frappe.db.delete("Additional Salary", {"ref_doctype": "Gratuity"}) make_earning_salary_component( @@ -76,6 +79,14 @@ class TestGratuity(unittest.TestCase): # additional salary creation (Pay via salary slip) self.assertTrue(frappe.db.exists("Additional Salary", {"ref_docname": gratuity.name})) + salary_slip = make_salary_slip("Test Gratuity", employee=employee) + salary_slip.posting_date = getdate() + salary_slip.insert() + salary_slip.submit() + + gratuity.reload() + self.assertEqual(gratuity.status, "Paid") + def test_check_gratuity_amount_based_on_all_previous_slabs(self): employee, sal_slip = create_employee_and_get_last_salary_slip() rule = get_gratuity_rule("Rule Under Limited Contract (UAE)") @@ -209,7 +220,13 @@ def create_employee_and_get_last_salary_slip(): frappe.db.set_value("Employee", employee, "relieving_date", getdate()) frappe.db.set_value("Employee", employee, "date_of_joining", add_days(getdate(), -(6 * 365))) if not frappe.db.exists("Salary Slip", {"employee": employee}): - salary_slip = make_employee_salary_slip("test_employee@salary.com", "Monthly") + posting_date = get_first_day(add_months(getdate(), -1)) + salary_slip = make_employee_salary_slip( + "test_employee@salary.com", "Monthly", "Test Gratuity", posting_date=posting_date + ) + salary_slip.start_date = posting_date + salary_slip.end_date = None + salary_slip.save() salary_slip.submit() salary_slip = salary_slip.name else: diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 1bc3741922..60ba2d9a07 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -997,7 +997,7 @@ class TestSalarySlip(unittest.TestCase): return [no_of_days_in_month[1], no_of_holidays_in_month] -def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): +def make_employee_salary_slip(user, payroll_frequency, salary_structure=None, posting_date=None): from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure if not salary_structure: @@ -1008,7 +1008,11 @@ def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): ) salary_structure_doc = make_salary_structure( - salary_structure, payroll_frequency, employee=employee.name, company=employee.company + salary_structure, + payroll_frequency, + employee=employee.name, + company=employee.company, + from_date=posting_date, ) salary_slip_name = frappe.db.get_value( "Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})} @@ -1018,7 +1022,7 @@ def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): salary_slip = make_salary_slip(salary_structure_doc.name, employee=employee.name) salary_slip.employee_name = employee.employee_name salary_slip.payroll_frequency = payroll_frequency - salary_slip.posting_date = nowdate() + salary_slip.posting_date = posting_date or nowdate() salary_slip.insert() else: salary_slip = frappe.get_doc("Salary Slip", salary_slip_name)