feat: employee initial work history updated when transfer is performed (#27768) (#28045)

* feat: employee initial work history updated when transfer is performed

* fix: sider

* fix: remove commit statement

* fix: tests and code formatting

* fix: tests

Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com>
(cherry picked from commit 03bfc77940)

Co-authored-by: Mohammed Yusuf Shaikh <49878143+mohammedyusufshaikh@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2021-10-21 10:34:31 +05:30
committed by GitHub
parent 4f5d67883c
commit e0f2130731
4 changed files with 121 additions and 9 deletions

View File

@@ -145,7 +145,15 @@ def set_employee_name(doc):
if doc.employee and not doc.employee_name:
doc.employee_name = frappe.db.get_value("Employee", doc.employee, "employee_name")
def update_employee(employee, details, date=None, cancel=False):
def update_employee_work_history(employee, details, date=None, cancel=False):
if not employee.internal_work_history and not cancel:
employee.append("internal_work_history", {
"branch": employee.branch,
"designation": employee.designation,
"department": employee.department,
"from_date": employee.date_of_joining
})
internal_work_history = {}
for item in details:
field = frappe.get_meta("Employee").get_field(item.fieldname)
@@ -160,11 +168,35 @@ def update_employee(employee, details, date=None, cancel=False):
setattr(employee, item.fieldname, new_data)
if item.fieldname in ["department", "designation", "branch"]:
internal_work_history[item.fieldname] = item.new
if internal_work_history and not cancel:
internal_work_history["from_date"] = date
employee.append("internal_work_history", internal_work_history)
if cancel:
delete_employee_work_history(details, employee, date)
return employee
def delete_employee_work_history(details, employee, date):
filters = {}
for d in details:
for history in employee.internal_work_history:
if d.property == "Department" and history.department == d.new:
department = d.new
filters["department"] = department
if d.property == "Designation" and history.designation == d.new:
designation = d.new
filters["designation"] = designation
if d.property == "Branch" and history.branch == d.new:
branch = d.new
filters["branch"] = branch
if date and date == history.from_date:
filters["from_date"] = date
if filters:
frappe.db.delete("Employee Internal Work History", filters)
@frappe.whitelist()
def get_employee_fields_label():
fields = []