fix: get fallback cost center from Employee/Department

This commit is contained in:
Nabin Hait
2021-12-24 17:34:34 +05:30
parent f152a40b28
commit f867f1974a
5 changed files with 15 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ frappe.ui.form.on('Department', {
"company": frm.doc.company, "company": frm.doc.company,
"is_group": 0 "is_group": 0
} }
} };
}); });
}, },
refresh: function(frm) { refresh: function(frm) {

View File

@@ -54,7 +54,7 @@ frappe.ui.form.on('Employee', {
"company": frm.doc.company, "company": frm.doc.company,
"is_group": 0 "is_group": 0
} }
} };
}); });
}, },
onload: function (frm) { onload: function (frm) {

View File

@@ -239,8 +239,14 @@ class PayrollEntry(Document):
cost_centers = dict(frappe.get_all("Employee Cost Center", {"parent": ss_assignment_name}, cost_centers = dict(frappe.get_all("Employee Cost Center", {"parent": ss_assignment_name},
["cost_center", "percentage"], as_list=1)) ["cost_center", "percentage"], as_list=1))
if not cost_centers: 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 = { cost_centers = {
self.cost_center: 100 default_cost_center: 100
} }
self.employee_cost_centers.setdefault(employee, cost_centers) self.employee_cost_centers.setdefault(employee, cost_centers)

View File

@@ -132,12 +132,12 @@ class TestPayrollEntry(unittest.TestCase):
"_Test Payroll Payable - _TC") "_Test Payroll Payable - _TC")
currency=frappe.db.get_value("Company", "_Test Company", "default_currency") 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) 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) 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 # update cost centers in salary structure assignment for employee2
ssa = frappe.db.get_value("Salary Structure Assignment", 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 = frappe.get_doc("Salary Structure Assignment", ssa)
ssa_doc.payroll_cost_centers = [] ssa_doc.payroll_cost_centers = []

View File

@@ -47,12 +47,12 @@ frappe.ui.form.on('Salary Structure Assignment', {
"company": frm.doc.company, "company": frm.doc.company,
"is_group": 0 "is_group": 0
} }
} };
}); });
}, },
employee: function(frm) { employee: function(frm) {
if(frm.doc.employee){ if (frm.doc.employee) {
frappe.call({ frappe.call({
method: "set_payroll_cost_centers", method: "set_payroll_cost_centers",
doc: frm.doc, doc: frm.doc,
@@ -61,7 +61,7 @@ frappe.ui.form.on('Salary Structure Assignment', {
} }
}); });
} }
else{ else {
frm.set_value("payroll_cost_centers", []); frm.set_value("payroll_cost_centers", []);
} }
}, },