brotherton-erpnext/erpnext/patches/v14_0/set_payroll_cost_centers.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
1.0 KiB
Python
Raw Normal View History

import frappe
2021-12-28 03:24:05 +00:00
def execute():
2021-12-28 03:24:05 +00:00
frappe.reload_doc("payroll", "doctype", "employee_cost_center")
frappe.reload_doc("payroll", "doctype", "salary_structure_assignment")
employees = frappe.get_all("Employee", fields=["department", "payroll_cost_center", "name"])
2021-12-28 03:24:05 +00:00
employee_cost_center = {}
for d in employees:
cost_center = d.payroll_cost_center
if not cost_center and d.department:
cost_center = frappe.get_cached_value("Department", d.department, "payroll_cost_center")
2021-12-28 03:24:05 +00:00
if cost_center:
employee_cost_center.setdefault(d.name, cost_center)
2021-12-28 03:24:05 +00:00
salary_structure_assignments = frappe.get_all(
"Salary Structure Assignment", filters={"docstatus": ["!=", 2]}, fields=["name", "employee"]
)
2021-12-28 03:24:05 +00:00
for d in salary_structure_assignments:
cost_center = employee_cost_center.get(d.employee)
if cost_center:
assignment = frappe.get_doc("Salary Structure Assignment", d.name)
if not assignment.get("payroll_cost_centers"):
assignment.append("payroll_cost_centers", {"cost_center": cost_center, "percentage": 100})
assignment.save()