40
40
make_salary_slip_from_timesheet ,
41
41
)
42
42
from hrms .payroll .doctype .salary_structure .salary_structure import make_salary_slip
43
- from hrms .tests .test_utils import get_first_sunday
43
+ from hrms .tests .test_utils import create_company , get_first_sunday
44
+
45
+ HOLIDAY_LIST = "Salary Slip Test Holiday List"
44
46
45
47
46
48
class TestSalarySlip (FrappeTestCase ):
@@ -62,9 +64,7 @@ def test_employee_status_inactive(self):
62
64
employee_doc .reload ()
63
65
64
66
make_holiday_list ()
65
- frappe .db .set_value (
66
- "Company" , employee_doc .company , "default_holiday_list" , "Salary Slip Test Holiday List"
67
- )
67
+ frappe .db .set_value ("Company" , employee_doc .company , "default_holiday_list" , HOLIDAY_LIST )
68
68
69
69
frappe .db .sql (
70
70
"""delete from `tabSalary Structure` where name='Test Inactive Employee Salary Slip'"""
@@ -228,7 +228,7 @@ def test_payment_days_for_mid_joinee_including_holidays_and_unmarked_days(self):
228
228
229
229
for days in range (date_diff (relieving_date , joining_date ) + 1 ):
230
230
date = add_days (joining_date , days )
231
- if not is_holiday ("Salary Slip Test Holiday List" , date ):
231
+ if not is_holiday (HOLIDAY_LIST , date ):
232
232
mark_attendance (new_emp_id , date , "Present" , ignore_validate = True )
233
233
else :
234
234
holidays += 1
@@ -274,7 +274,7 @@ def test_payment_days_for_mid_joinee_excluding_holidays(self):
274
274
275
275
for days in range (date_diff (relieving_date , joining_date ) + 1 ):
276
276
date = add_days (joining_date , days )
277
- if not is_holiday ("Salary Slip Test Holiday List" , date ):
277
+ if not is_holiday (HOLIDAY_LIST , date ):
278
278
mark_attendance (new_emp_id , date , "Present" , ignore_validate = True )
279
279
else :
280
280
holidays += 1
@@ -338,7 +338,7 @@ def test_payment_days_in_salary_slip_based_on_timesheet(self):
338
338
emp = make_employee (
339
339
340
340
company = "_Test Company" ,
341
- holiday_list = "Salary Slip Test Holiday List" ,
341
+ holiday_list = HOLIDAY_LIST ,
342
342
)
343
343
frappe .db .set_value ("Employee" , emp , {"relieving_date" : None , "status" : "Active" })
344
344
@@ -1484,6 +1484,60 @@ def test_variable_tax_component(self):
1484
1484
self .assertEqual (test_tds .accounts [0 ].company , salary_slip .company )
1485
1485
self .assertListEqual (tax_component , ["_Test TDS" ])
1486
1486
1487
+ def test_get_income_tax_slabs (self ):
1488
+ from hrms .payroll .doctype .salary_structure .test_salary_structure import make_salary_structure
1489
+
1490
+ company = create_company ("_Test Tax Slab" ).name
1491
+ frappe .db .delete ("Payroll Period" , {"company" : company })
1492
+ employee = make_employee (
"[email protected] " ,
company = company ,
holiday_list = HOLIDAY_LIST )
1493
+
1494
+ fiscal_year = get_fiscal_year (getdate (), as_dict = True )
1495
+ year_start , year_end = fiscal_year .year_start_date , fiscal_year .year_end_date
1496
+ mid_year = add_months (year_start , 6 )
1497
+
1498
+ payroll_period = create_payroll_period (
1499
+ name = "Payroll Period Test" ,
1500
+ company = company ,
1501
+ start_date = year_start ,
1502
+ end_date = year_end ,
1503
+ )
1504
+
1505
+ tax_slabs = []
1506
+ salary_structures = []
1507
+ for start_date , end_date in [(year_start , mid_year ), (mid_year , year_end )]:
1508
+ tax_slab = create_tax_slab (
1509
+ payroll_period ,
1510
+ allow_tax_exemption = True ,
1511
+ currency = "INR" ,
1512
+ effective_date = getdate (start_date ),
1513
+ company = company ,
1514
+ )
1515
+ tax_slabs .append (tax_slab )
1516
+ salary_structure = make_salary_structure (
1517
+ f"Structure { start_date } " ,
1518
+ "Monthly" ,
1519
+ employee = employee ,
1520
+ company = company ,
1521
+ currency = "INR" ,
1522
+ from_date = start_date ,
1523
+ payroll_period = payroll_period ,
1524
+ allow_duplicate = True ,
1525
+ )
1526
+ salary_structures .append (salary_structure )
1527
+
1528
+ # fetches the correct tax slab for backdated salary slip
1529
+ salary_slip = make_salary_slip (
1530
+ salary_structures [0 ].name , employee = employee , posting_date = year_start
1531
+ )
1532
+ salary_slip .insert ()
1533
+ self .assertEqual (salary_slip .get_income_tax_slabs ().name , tax_slabs [0 ])
1534
+
1535
+ salary_slip = make_salary_slip (
1536
+ salary_structures [1 ].name , employee = employee , posting_date = add_days (mid_year , 1 )
1537
+ )
1538
+ salary_slip .insert ()
1539
+ self .assertEqual (salary_slip .get_income_tax_slabs ().name , tax_slabs [1 ])
1540
+
1487
1541
1488
1542
class TestSalarySlipSafeEval (FrappeTestCase ):
1489
1543
def test_safe_eval_for_salary_slip (self ):
@@ -1575,10 +1629,13 @@ def make_employee_salary_slip(emp_id, payroll_frequency, salary_structure=None,
1575
1629
salary_slip_name = frappe .db .get_value ("Salary Slip" , {"employee" : emp_id })
1576
1630
1577
1631
if not salary_slip_name :
1578
- salary_slip = make_salary_slip (salary_structure_doc .name , employee = employee .name )
1632
+ date = posting_date or nowdate ()
1633
+ salary_slip = make_salary_slip (
1634
+ salary_structure_doc .name , employee = employee .name , posting_date = date
1635
+ )
1579
1636
salary_slip .employee_name = employee .employee_name
1580
1637
salary_slip .payroll_frequency = payroll_frequency
1581
- salary_slip .posting_date = posting_date or nowdate ()
1638
+ salary_slip .posting_date = date
1582
1639
salary_slip .insert ()
1583
1640
else :
1584
1641
salary_slip = frappe .get_doc ("Salary Slip" , salary_slip_name )
@@ -2011,7 +2068,7 @@ def setup_test():
2011
2068
make_payroll_period ()
2012
2069
2013
2070
frappe .db .set_value (
2014
- "Company" , erpnext .get_default_company (), "default_holiday_list" , "Salary Slip Test Holiday List"
2071
+ "Company" , erpnext .get_default_company (), "default_holiday_list" , HOLIDAY_LIST
2015
2072
)
2016
2073
2017
2074
frappe .db .set_value ("Payroll Settings" , None , "email_salary_slip_to_employee" , 0 )
@@ -2041,7 +2098,7 @@ def make_payroll_period():
2041
2098
2042
2099
def make_holiday_list (list_name = None , from_date = None , to_date = None , add_weekly_offs = True ):
2043
2100
fiscal_year = get_fiscal_year (nowdate (), company = erpnext .get_default_company ())
2044
- name = list_name or "Salary Slip Test Holiday List"
2101
+ name = list_name or HOLIDAY_LIST
2045
2102
2046
2103
frappe .delete_doc_if_exists ("Holiday List" , name , force = True )
2047
2104
0 commit comments