-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: employee cost center breakup in payroll
(cherry picked from commit c036831)
- Loading branch information
1 parent
ae1236f
commit 182de68
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ def setUp(self): | |
"Payroll Entry", | ||
"Salary Structure", | ||
"Salary Structure Assignment", | ||
"Employee Cost Center", | ||
"Payroll Employee Detail", | ||
"Additional Salary", | ||
]: | ||
|
@@ -181,6 +182,57 @@ def test_payroll_entry_with_employee_cost_center(self): | |
|
||
self.assertEqual(je_entries, expected_je) | ||
|
||
@change_settings("Payroll Settings", {"process_payroll_accounting_entry_based_on_employee": 0}) | ||
def test_employee_cost_center_breakup(self): | ||
"""Test only the latest salary structure assignment is considered for cost center breakup""" | ||
COMPANY = "_Test Company" | ||
COST_CENTERS = {"_Test Cost Center - _TC": 60, "_Test Cost Center 2 - _TC": 40} | ||
department = create_department("Cost Center Test") | ||
employee = make_employee("[email protected]", department=department, company=COMPANY) | ||
salary_structure = make_salary_structure( | ||
"_Test Salary Structure 2", | ||
"Monthly", | ||
employee, | ||
company=COMPANY, | ||
) | ||
|
||
# update cost centers in salary structure assignment for employee | ||
new_assignment = frappe.db.get_value( | ||
"Salary Structure Assignment", | ||
{"employee": employee, "salary_structure": salary_structure.name, "docstatus": 1}, | ||
"name", | ||
) | ||
new_assignment = frappe.get_doc("Salary Structure Assignment", new_assignment) | ||
new_assignment.payroll_cost_centers = [] | ||
for cost_center, percentage in COST_CENTERS.items(): | ||
new_assignment.append( | ||
"payroll_cost_centers", {"cost_center": cost_center, "percentage": percentage} | ||
) | ||
new_assignment.save() | ||
|
||
# make an old salary structure assignment to test and ensure old cost center mapping is excluded | ||
old_assignment = frappe.copy_doc(new_assignment) | ||
old_assignment.from_date = add_months(new_assignment.from_date, -1) | ||
old_assignment.payroll_cost_centers = [] | ||
old_assignment.append("payroll_cost_centers", {"cost_center": "Main - _TC", "percentage": 100}) | ||
old_assignment.submit() | ||
|
||
dates = get_start_end_dates("Monthly", nowdate()) | ||
pe = make_payroll_entry( | ||
start_date=dates.start_date, | ||
end_date=dates.end_date, | ||
payable_account="_Test Payroll Payable - _TC", | ||
currency="INR", | ||
department=department, | ||
company="_Test Company", | ||
payment_account="Cash - _TC", | ||
cost_center="Main - _TC", | ||
) | ||
|
||
# only new cost center breakup is considered | ||
cost_centers = pe.get_payroll_cost_centers_for_employee(employee, "_Test Salary Structure 2") | ||
self.assertEqual(cost_centers, COST_CENTERS) | ||
|
||
def test_get_end_date(self): | ||
self.assertEqual(get_end_date("2017-01-01", "monthly"), {"end_date": "2017-01-31"}) | ||
self.assertEqual(get_end_date("2017-02-01", "monthly"), {"end_date": "2017-02-28"}) | ||
|