[Fix] Salary Slip Test cases fix
This commit is contained in:
parent
eb879556ed
commit
0ece9e0e2e
@ -243,16 +243,15 @@ class SalarySlip(TransactionBase):
|
||||
|
||||
def get_payment_days(self, joining_date, relieving_date):
|
||||
start_date = getdate(self.start_date)
|
||||
|
||||
if joining_date:
|
||||
if joining_date > getdate(self.start_date):
|
||||
if getdate(self.start_date) <= joining_date <= getdate(self.end_date):
|
||||
start_date = joining_date
|
||||
elif joining_date > getdate(self.end_date):
|
||||
return
|
||||
|
||||
end_date = getdate(self.end_date)
|
||||
if relieving_date:
|
||||
if relieving_date > start_date and relieving_date < getdate(self.end_date):
|
||||
if getdate(self.start_date) <= relieving_date <= getdate(self.end_date):
|
||||
end_date = relieving_date
|
||||
elif relieving_date < getdate(self.start_date):
|
||||
frappe.throw(_("Employee relieved on {0} must be set as 'Left'")
|
||||
@ -263,7 +262,6 @@ class SalarySlip(TransactionBase):
|
||||
if not cint(frappe.db.get_value("HR Settings", None, "include_holidays_in_total_working_days")):
|
||||
holidays = self.get_holidays_for_employee(start_date, end_date)
|
||||
payment_days -= len(holidays)
|
||||
|
||||
return payment_days
|
||||
|
||||
def get_holidays_for_employee(self, start_date, end_date):
|
||||
|
@ -1,45 +0,0 @@
|
||||
[
|
||||
{
|
||||
"company": "_Test Company",
|
||||
"doctype": "Salary Slip",
|
||||
"deductions": [
|
||||
{
|
||||
"doctype": "Salary Detail",
|
||||
"amount": 100,
|
||||
"depends_on_lwp": 0,
|
||||
"salary_component": "_Test Professional Tax",
|
||||
"parentfield": "deductions"
|
||||
},
|
||||
{
|
||||
"doctype": "Salary Detail",
|
||||
"amount": 48.39,
|
||||
"depends_on_lwp": 0,
|
||||
"salary_component": "_Test TDS",
|
||||
"parentfield": "deductions"
|
||||
}
|
||||
],
|
||||
"earnings": [
|
||||
{
|
||||
"doctype": "Salary Detail",
|
||||
"amount": 14516.13,
|
||||
"depends_on_lwp": 0,
|
||||
"salary_component": "_Test Basic Salary",
|
||||
"parentfield": "earnings"
|
||||
},
|
||||
{
|
||||
"doctype": "Salary Detail",
|
||||
"amount": 500,
|
||||
"depends_on_lwp": 0,
|
||||
"salary_component": "_Test Allowance",
|
||||
"parentfield": "earnings"
|
||||
}
|
||||
],
|
||||
"employee": "_T-Employee-0001",
|
||||
"employee_name": "_Test Employee",
|
||||
"posting_date": "2013-02-01",
|
||||
"fiscal_year": "_Test Fiscal Year 2013",
|
||||
"month": "01",
|
||||
"payment_days": 31,
|
||||
"total_working_days": 31
|
||||
}
|
||||
]
|
@ -5,9 +5,9 @@ from __future__ import unicode_literals
|
||||
import unittest
|
||||
import frappe
|
||||
import erpnext
|
||||
from frappe.utils.make_random import get_random
|
||||
import calendar
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
from frappe.utils import today, now_datetime, getdate, cstr, add_years, nowdate, add_days
|
||||
from frappe.utils import getdate, nowdate, add_days
|
||||
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
|
||||
from erpnext.hr.doctype.process_payroll.test_process_payroll import get_salary_component_account
|
||||
from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
|
||||
@ -24,17 +24,13 @@ class TestSalarySlip(unittest.TestCase):
|
||||
|
||||
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List")
|
||||
|
||||
from erpnext.hr.doctype.leave_application.test_leave_application import _test_records as leave_applications
|
||||
la = frappe.copy_doc(leave_applications[2])
|
||||
la.insert()
|
||||
la.status = "Approved"
|
||||
la.submit()
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
def test_salary_slip_with_holidays_included(self):
|
||||
no_of_days = self.get_no_of_days()
|
||||
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
|
||||
self.make_employee("test_employee@salary.com")
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
|
||||
@ -42,8 +38,8 @@ class TestSalarySlip(unittest.TestCase):
|
||||
ss = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
|
||||
|
||||
self.assertEquals(ss.total_working_days, 31)
|
||||
self.assertEquals(ss.payment_days, 31)
|
||||
self.assertEquals(ss.total_working_days, no_of_days[0])
|
||||
self.assertEquals(ss.payment_days, no_of_days[0])
|
||||
self.assertEquals(ss.earnings[0].amount, 5000)
|
||||
self.assertEquals(ss.earnings[1].amount, 3000)
|
||||
self.assertEquals(ss.deductions[0].amount, 5000)
|
||||
@ -52,6 +48,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
self.assertEquals(ss.net_pay, 3000)
|
||||
|
||||
def test_salary_slip_with_holidays_excluded(self):
|
||||
no_of_days = self.get_no_of_days()
|
||||
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
|
||||
self.make_employee("test_employee@salary.com")
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
|
||||
@ -59,8 +56,8 @@ class TestSalarySlip(unittest.TestCase):
|
||||
ss = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
|
||||
|
||||
self.assertEquals(ss.total_working_days, 28)
|
||||
self.assertEquals(ss.payment_days, 28)
|
||||
self.assertEquals(ss.total_working_days, no_of_days[0] - no_of_days[1])
|
||||
self.assertEquals(ss.payment_days, no_of_days[0] - no_of_days[1])
|
||||
self.assertEquals(ss.earnings[0].amount, 5000)
|
||||
self.assertEquals(ss.earnings[0].default_amount, 5000)
|
||||
self.assertEquals(ss.earnings[1].amount, 3000)
|
||||
@ -70,37 +67,46 @@ class TestSalarySlip(unittest.TestCase):
|
||||
self.assertEquals(ss.net_pay, 3000)
|
||||
|
||||
def test_payment_days(self):
|
||||
no_of_days = self.get_no_of_days()
|
||||
# Holidays not included in working days
|
||||
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
|
||||
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
|
||||
|
||||
# set joinng date in the same month
|
||||
self.make_employee("test_employee@salary.com")
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", "2013-01-11")
|
||||
if getdate(nowdate()).day > 15:
|
||||
date_of_joining = getdate(add_days(nowdate(),-10))
|
||||
relieving_date = getdate(add_days(nowdate(),-10))
|
||||
elif getdate(nowdate()).day < 15 and getdate(nowdate()).day > 5:
|
||||
date_of_joining = getdate(add_days(nowdate(),-3))
|
||||
relieving_date = getdate(add_days(nowdate(),-3))
|
||||
elif getdate(nowdate()).day < 5 and not getdate(nowdate()).day == 1:
|
||||
date_of_joining = getdate(add_days(nowdate(),-1))
|
||||
relieving_date = getdate(add_days(nowdate(),-1))
|
||||
elif getdate(nowdate()).day == 1:
|
||||
date_of_joining = getdate(nowdate())
|
||||
relieving_date = getdate(nowdate())
|
||||
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", date_of_joining)
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
|
||||
|
||||
ss = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
|
||||
|
||||
self.assertEquals(ss.total_working_days, 28)
|
||||
self.assertEquals(ss.payment_days, 28)
|
||||
self.assertEquals(ss.total_working_days, no_of_days[0])
|
||||
self.assertEquals(ss.payment_days, (no_of_days[0] - getdate(date_of_joining).day + 1))
|
||||
|
||||
# set relieving date in the same month
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", "12-12-2016")
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", (add_days(nowdate(),-60)))
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", relieving_date)
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Left")
|
||||
|
||||
self.assertEquals(ss.total_working_days, 28)
|
||||
self.assertEquals(ss.payment_days, 28)
|
||||
ss.save()
|
||||
|
||||
self.assertEquals(ss.total_working_days, no_of_days[0])
|
||||
self.assertEquals(ss.payment_days, getdate(relieving_date).day)
|
||||
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
|
||||
# Holidays included in working days
|
||||
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
|
||||
self.assertEquals(ss.total_working_days, 28)
|
||||
self.assertEquals(ss.payment_days, 28)
|
||||
ss.save()
|
||||
#
|
||||
# frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", "2001-01-11")
|
||||
# frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
|
||||
|
||||
def test_employee_salary_slip_read_permission(self):
|
||||
self.make_employee("test_employee@salary.com")
|
||||
@ -126,7 +132,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
|
||||
def test_payroll_frequency(self):
|
||||
fiscal_year = get_fiscal_year(nowdate())[0]
|
||||
month = "%02d" % getdate(nowdate()).month or "%02d" % getdate(nowdate()).month
|
||||
month = "%02d" % getdate(nowdate()).month
|
||||
m = get_month_details(fiscal_year, month)
|
||||
|
||||
for payroll_frequncy in ["Monthly", "Bimonthly", "Fortnightly", "Weekly", "Daily"]:
|
||||
@ -176,12 +182,13 @@ class TestSalarySlip(unittest.TestCase):
|
||||
}).insert()
|
||||
|
||||
def make_holiday_list(self):
|
||||
fiscal_year = get_fiscal_year(nowdate())
|
||||
if not frappe.db.get_value("Holiday List", "Salary Slip Test Holiday List"):
|
||||
holiday_list = frappe.get_doc({
|
||||
"doctype": "Holiday List",
|
||||
"holiday_list_name": "Salary Slip Test Holiday List",
|
||||
"from_date": nowdate(),
|
||||
"to_date": add_years(nowdate(), 1),
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"weekly_off": "Sunday"
|
||||
}).insert()
|
||||
holiday_list.get_weekly_off_dates()
|
||||
@ -211,6 +218,14 @@ class TestSalarySlip(unittest.TestCase):
|
||||
activity_type.wage_rate = 25
|
||||
activity_type.save()
|
||||
|
||||
def get_no_of_days(self):
|
||||
no_of_days_in_month = calendar.monthrange(getdate(nowdate()).year,
|
||||
getdate(nowdate()).month)
|
||||
no_of_holidays_in_month = len([1 for i in calendar.monthcalendar(getdate(nowdate()).year,
|
||||
getdate(nowdate()).month) if i[6] != 0])
|
||||
return [no_of_days_in_month[1], no_of_holidays_in_month]
|
||||
|
||||
|
||||
def make_earning_salary_component(salary_components):
|
||||
for salary_component in salary_components:
|
||||
if not frappe.db.exists('Salary Component', salary_component):
|
||||
@ -318,7 +333,4 @@ def get_deductions_component():
|
||||
"formula": 'base*.1',
|
||||
"idx": 3
|
||||
}
|
||||
]
|
||||
|
||||
test_dependencies = ["Leave Application", "Holiday List"]
|
||||
|
||||
]
|
@ -9,25 +9,15 @@ from frappe.utils.make_random import get_random
|
||||
from frappe.utils import nowdate, add_days, add_years
|
||||
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
|
||||
from erpnext.hr.doctype.salary_slip.test_salary_slip import make_earning_salary_component, make_deduction_salary_component
|
||||
# test_records = frappe.get_test_records('Salary Structure')
|
||||
|
||||
class TestSalaryStructure(unittest.TestCase):
|
||||
def test_setup(self):
|
||||
if not frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2016"):
|
||||
fy = frappe.get_doc({
|
||||
"doctype": "Fiscal Year",
|
||||
"year": "_Test Fiscal Year 2016",
|
||||
"year_end_date": "2016-12-31",
|
||||
"year_start_date": "2016-01-01"
|
||||
})
|
||||
fy.insert()
|
||||
|
||||
self.make_holiday_list()
|
||||
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Structure Test Holiday List")
|
||||
make_earning_salary_component(["Basic Salary", "Allowance", "HRA"])
|
||||
make_deduction_salary_component(["Professional Tax", "TDS"])
|
||||
employee1 = self.make_employee("test_employee@salary.com")
|
||||
employee2 = self.make_employee("test_employee_2@salary.com")
|
||||
self.make_employee("test_employee@salary.com")
|
||||
self.make_employee("test_employee_2@salary.com")
|
||||
|
||||
def make_holiday_list(self):
|
||||
if not frappe.db.get_value("Holiday List", "Salary Structure Test Holiday List"):
|
||||
@ -88,8 +78,7 @@ def make_salary_slip_from_salary_structure(employee):
|
||||
sal_struct = make_salary_structure('Salary Structure Sample')
|
||||
sal_slip = make_salary_slip(sal_struct, employee = employee)
|
||||
sal_slip.employee_name = frappe.get_value("Employee", {"name":employee}, "employee_name")
|
||||
sal_slip.month = "11"
|
||||
sal_slip.fiscal_year = "_Test Fiscal Year 2016"
|
||||
sal_slip.start_date = nowdate()
|
||||
sal_slip.posting_date = nowdate()
|
||||
sal_slip.payroll_frequency = "Monthly"
|
||||
sal_slip.insert()
|
||||
|
Loading…
Reference in New Issue
Block a user