Employee Transfer allow same company, update internal work history (#14430)

This commit is contained in:
Ranjith Kurungadam 2018-06-11 11:24:44 +05:30 committed by Nabin Hait
parent 88a90ff3b5
commit e46639f47c
3 changed files with 18 additions and 11 deletions

View File

@ -21,10 +21,10 @@ class EmployeePromotion(Document):
def on_submit(self):
employee = frappe.get_doc("Employee", self.employee)
employee = update_employee(employee, self.promotion_details)
employee = update_employee(employee, self.promotion_details, date=self.promotion_date)
employee.save()
def on_cancel(self):
employee = frappe.get_doc("Employee", self.employee)
employee = update_employee(employee, self.promotion_details, True)
employee = update_employee(employee, self.promotion_details, cancel=True)
employee.save()

View File

@ -13,8 +13,6 @@ class EmployeeTransfer(Document):
def validate(self):
if frappe.get_value("Employee", self.employee, "status") == "Left":
frappe.throw(_("Cannot transfer Employee with status Left"))
if self.new_company and self.company == self.new_company:
frappe.throw(_("New Company must be different from current company"))
def before_submit(self):
if getdate(self.transfer_date) > getdate():
@ -27,7 +25,9 @@ class EmployeeTransfer(Document):
new_employee = frappe.copy_doc(employee)
new_employee.name = None
new_employee.employee_number = None
new_employee = update_employee(new_employee, self.transfer_details)
if self.company != self.new_company:
new_employee.internal_work_history = []
new_employee = update_employee(new_employee, self.transfer_details, date=self.transfer_date)
if self.new_company:
new_employee.company = self.new_company
#move user_id to new employee before insert
@ -40,7 +40,7 @@ class EmployeeTransfer(Document):
employee.db_set("relieving_date", self.transfer_date)
employee.db_set("status", "Left")
else:
employee = update_employee(employee, self.transfer_details)
employee = update_employee(employee, self.transfer_details, date=self.transfer_date)
if self.new_company:
employee.company = self.new_company
employee.save()
@ -54,10 +54,11 @@ class EmployeeTransfer(Document):
#mark the employee as active
employee.status = "Active"
employee.relieving_date = ''
employee.save()
else:
employee = update_employee(employee, self.transfer_details, True)
employee.save()
employee = update_employee(employee, self.transfer_details, cancel=True)
if self.new_company != self.company:
employee.company = self.company
employee.save()
def validate_user_in_details(self):
for item in self.transfer_details:

View File

@ -88,7 +88,8 @@ 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, cancel=False):
def update_employee(employee, details, date=None, cancel=False):
internal_work_history = {}
for item in details:
fieldtype = frappe.get_meta("Employee").get_field(item.fieldname).fieldtype
new_data = item.new if not cancel else item.current
@ -97,6 +98,11 @@ def update_employee(employee, details, cancel=False):
elif fieldtype =="Datetime" and new_data:
new_data = get_datetime(new_data)
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)
return employee
@frappe.whitelist()
@ -343,4 +349,4 @@ def get_annual_component_pay(frequency, amount):
elif frequency == "Monthly":
return amount * 12
elif frequency == "Bimonthly":
return amount * 6
return amount * 6