fix: get fallback cost center from Employee/Department
diff --git a/erpnext/hr/doctype/department/department.js b/erpnext/hr/doctype/department/department.js
index eb759a3..46cfbda 100644
--- a/erpnext/hr/doctype/department/department.js
+++ b/erpnext/hr/doctype/department/department.js
@@ -13,7 +13,7 @@
"company": frm.doc.company,
"is_group": 0
}
- }
+ };
});
},
refresh: function(frm) {
diff --git a/erpnext/hr/doctype/employee/employee.js b/erpnext/hr/doctype/employee/employee.js
index 4181e0f..8c73e9c 100755
--- a/erpnext/hr/doctype/employee/employee.js
+++ b/erpnext/hr/doctype/employee/employee.js
@@ -54,7 +54,7 @@
"company": frm.doc.company,
"is_group": 0
}
- }
+ };
});
},
onload: function (frm) {
diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py
index 6aa11bc..f61e688 100644
--- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py
+++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py
@@ -239,8 +239,14 @@
cost_centers = dict(frappe.get_all("Employee Cost Center", {"parent": ss_assignment_name},
["cost_center", "percentage"], as_list=1))
if not cost_centers:
+ default_cost_center, department = frappe.get_cached_value("Employee", employee, ["payroll_cost_center", "department"])
+ if not default_cost_center and department:
+ default_cost_center = frappe.get_cached_value("Department", department, "payroll_cost_center")
+ if not default_cost_center:
+ default_cost_center = self.cost_center
+
cost_centers = {
- self.cost_center: 100
+ default_cost_center: 100
}
self.employee_cost_centers.setdefault(employee, cost_centers)
diff --git a/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py
index a3bc164..e88a2ca 100644
--- a/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py
+++ b/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py
@@ -132,12 +132,12 @@
"_Test Payroll Payable - _TC")
currency=frappe.db.get_value("Company", "_Test Company", "default_currency")
- ss1 = make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=currency, test_tax=False)
- ss2 = make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False)
+ make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=currency, test_tax=False)
+ ss = make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False)
# update cost centers in salary structure assignment for employee2
ssa = frappe.db.get_value("Salary Structure Assignment",
- {"employee": employee2, "salary_structure": ss2.name, "docstatus": 1}, 'name')
+ {"employee": employee2, "salary_structure": ss.name, "docstatus": 1}, 'name')
ssa_doc = frappe.get_doc("Salary Structure Assignment", ssa)
ssa_doc.payroll_cost_centers = []
diff --git a/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js b/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js
index f6cb503..220bfbf 100644
--- a/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js
+++ b/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js
@@ -47,12 +47,12 @@
"company": frm.doc.company,
"is_group": 0
}
- }
+ };
});
},
employee: function(frm) {
- if(frm.doc.employee){
+ if (frm.doc.employee) {
frappe.call({
method: "set_payroll_cost_centers",
doc: frm.doc,
@@ -61,7 +61,7 @@
}
});
}
- else{
+ else {
frm.set_value("payroll_cost_centers", []);
}
},