diff --git a/erpnext/hr/doctype/appraisal/appraisal.py b/erpnext/hr/doctype/appraisal/appraisal.py index 31ca34c465..72bfc1ce69 100644 --- a/erpnext/hr/doctype/appraisal/appraisal.py +++ b/erpnext/hr/doctype/appraisal/appraisal.py @@ -9,12 +9,14 @@ from frappe.utils import flt, getdate from frappe import _ from frappe.model.mapper import get_mapped_doc from frappe.model.document import Document +from erpnext.hr.utils import set_employee_name class Appraisal(Document): def validate(self): if not self.status: self.status = "Draft" + set_employee_name(self) self.validate_dates() self.validate_existing_appraisal() self.calculate_total() diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py index ea9f27131f..dbab09796c 100644 --- a/erpnext/hr/doctype/attendance/attendance.py +++ b/erpnext/hr/doctype/attendance/attendance.py @@ -7,6 +7,7 @@ import frappe from frappe.utils import getdate, nowdate from frappe import _ from frappe.model.document import Document +from erpnext.hr.utils import set_employee_name class Attendance(Document): def validate_duplicate_record(self): @@ -16,6 +17,8 @@ class Attendance(Document): if res: frappe.throw(_("Attendance for employee {0} is already marked").format(self.employee)) + set_employee_name(self) + def check_leave_record(self): if self.status == 'Present': leave = frappe.db.sql("""select name from `tabLeave Application` diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 8250e51ede..fda3cf6aed 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -5,11 +5,13 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document +from erpnext.hr.utils import set_employee_name class ExpenseClaim(Document): def validate(self): self.validate_fiscal_year() self.validate_exp_details() + set_employee_name(self) def on_submit(self): if self.approval_status=="Draft": diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index 32cfd868e9..ef49eb9dd1 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -5,8 +5,8 @@ from __future__ import unicode_literals import frappe from frappe.utils import cint, flt from frappe import _ - from frappe.model.document import Document +from erpnext.hr.utils import set_employee_name class LeaveAllocation(Document): def validate(self): @@ -15,6 +15,8 @@ class LeaveAllocation(Document): if not self.total_leaves_allocated: self.total_leaves_allocated = self.new_leaves_allocated + set_employee_name(self) + def on_update_after_submit(self): self.validate_new_leaves_allocated_value() diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 863b2c6b22..18c1e11aa7 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -8,6 +8,7 @@ from frappe import _ from frappe.utils import cint, cstr, date_diff, flt, formatdate, getdate, get_url_to_form, \ comma_or, get_fullname from frappe import msgprint +from erpnext.hr.utils import set_employee_name class LeaveDayBlockedError(frappe.ValidationError): pass class OverlapError(frappe.ValidationError): pass @@ -22,6 +23,8 @@ class LeaveApplication(Document): else: self.previous_doc = None + set_employee_name(self) + self.validate_to_date() self.validate_balance_leaves() self.validate_leave_overlap() diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py index 232d6a9840..3f4b5e3080 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -9,7 +9,7 @@ from frappe.model.naming import make_autoname from frappe import msgprint, _ from erpnext.setup.utils import get_company_currency - +from erpnext.hr.utils import set_employee_name from erpnext.utilities.transaction_base import TransactionBase @@ -146,6 +146,8 @@ class SalarySlip(TransactionBase): company_currency = get_company_currency(self.company) self.total_in_words = money_in_words(self.rounded_total, company_currency) + set_employee_name(self) + def calculate_earning_total(self): self.gross_pay = flt(self.arrear_amount) + flt(self.leave_encashment_amount) for d in self.get("earning_details"): diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.py b/erpnext/hr/doctype/salary_structure/salary_structure.py index d170d0564e..f3d2eb1184 100644 --- a/erpnext/hr/doctype/salary_structure/salary_structure.py +++ b/erpnext/hr/doctype/salary_structure/salary_structure.py @@ -9,6 +9,7 @@ from frappe.model.naming import make_autoname from frappe import _ from frappe.model.mapper import get_mapped_doc from frappe.model.document import Document +from erpnext.hr.utils import set_employee_name class SalaryStructure(Document): def autoname(self): @@ -63,6 +64,7 @@ class SalaryStructure(Document): def validate(self): self.check_existing() self.validate_amount() + set_employee_name(self) @frappe.whitelist() def make_salary_slip(source_name, target_doc=None): diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index 87a9e0b68a..857f936e9e 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -22,3 +22,7 @@ def get_expense_approver_list(): if not roles: frappe.msgprint(_("No Expense Approvers. Please assign 'Expense Approver' Role to atleast one user")) return roles + +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")