diff --git a/erpnext/hr/doctype/department/department.json b/erpnext/hr/doctype/department/department.json index 664679d3f1..75f410fecd 100644 --- a/erpnext/hr/doctype/department/department.json +++ b/erpnext/hr/doctype/department/department.json @@ -3,7 +3,7 @@ "allow_guest_to_view": 0, "allow_import": 1, "allow_rename": 1, - "autoname": "", + "autoname": "", "beta": 0, "creation": "2013-02-05 11:48:26", "custom": 0, @@ -14,6 +14,7 @@ "fields": [ { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -46,6 +47,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -78,6 +80,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -110,6 +113,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 1, "collapsible": 0, @@ -141,6 +145,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -171,6 +176,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -203,6 +209,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -234,12 +241,13 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, "columns": 0, "description": "The first Leave Approver in the list will be set as the default Leave Approver.", - "fieldname": "leave_approver", + "fieldname": "leave_approvers", "fieldtype": "Table", "hidden": 0, "ignore_user_permissions": 0, @@ -267,6 +275,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -298,12 +307,13 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, "columns": 0, "description": "The first Expense Approver in the list will be set as the default Expense Approver.", - "fieldname": "expense_approver", + "fieldname": "expense_approvers", "fieldtype": "Table", "hidden": 0, "ignore_user_permissions": 0, @@ -331,6 +341,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -362,6 +373,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -393,6 +405,7 @@ }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -434,7 +447,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-05-11 12:18:18.839182", + "modified": "2018-06-13 15:50:04.611365", "modified_by": "Administrator", "module": "HR", "name": "Department", diff --git a/erpnext/hr/doctype/department_approver/department_approver.py b/erpnext/hr/doctype/department_approver/department_approver.py index d30d801491..f8ed5f98e1 100644 --- a/erpnext/hr/doctype/department_approver/department_approver.py +++ b/erpnext/hr/doctype/department_approver/department_approver.py @@ -28,9 +28,9 @@ def get_approvers(doctype, txt, searchfield, start, page_len, filters): order by lft desc""", (department_details.lft, department_details.rgt), as_list = True) if filters.get("doctype") == "Leave Application": - parentfield = "leave_approver" + parentfield = "leave_approvers" else: - parentfield = "expense_approver" + parentfield = "expense_approvers" if department_list: for d in department_list: approvers += frappe.db.sql("""select user.name, user.first_name, user.last_name from diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 747782931e..d6d8b1c73a 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -406,7 +406,7 @@ def get_leaves_for_period(employee, leave_type, from_date, to_date, status): select employee, leave_type, from_date, to_date, total_leave_days from `tabLeave Application` where employee=%(employee)s and leave_type=%(leave_type)s - and status = %(status)s + and status = %(status)s and docstatus != 2 and (from_date between %(from_date)s and %(to_date)s or to_date between %(from_date)s and %(to_date)s or (from_date < %(from_date)s and to_date > %(to_date)s)) @@ -617,4 +617,4 @@ def get_leave_approver(employee, department=None): if department: return frappe.db.get_value('Department Approver', {'parent': department, - 'parentfield': 'leave_approver', 'idx': 1}, 'approver') + 'parentfield': 'leave_approvers', 'idx': 1}, 'approver') diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index db46856fed..201660534e 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -413,7 +413,7 @@ def get_employee(): def set_leave_approver(): employee = get_employee() dept_doc = frappe.get_doc("Department", employee.department) - dept_doc.append('leave_approver', { + dept_doc.append('leave_approvers', { 'approver': 'test@example.com' }) dept_doc.save(ignore_permissions=True) diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py index a603015657..7d80817e1e 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py @@ -72,6 +72,6 @@ def get_approvers(department): # retrieve approvers list from current department and from its subsequent child departments for d in department_list: approvers.extend([l.leave_approver for l in frappe.db.sql("""select approver from `tabDepartment Approver` \ - where parent = %s and parentfield = 'leave_approver'""", (d), as_dict=True)]) + where parent = %s and parentfield = 'leave_approvers'""", (d), as_dict=True)]) return approvers diff --git a/erpnext/patches.txt b/erpnext/patches.txt index eb29528ac7..33a7913363 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -516,7 +516,7 @@ erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract erpnext.patches.v11_0.add_index_on_nestedset_doctypes erpnext.patches.v11_0.remove_modules_setup_page erpnext.patches.v11_0.rename_employee_loan_to_loan -erpnext.patches.v11_0.move_leave_approvers_from_employee +erpnext.patches.v11_0.move_leave_approvers_from_employee #13-06-2018 erpnext.patches.v11_0.update_department_lft_rgt erpnext.patches.v11_0.add_default_email_template_for_leave erpnext.patches.v11_0.set_default_email_template_in_hr #08-06-2018 diff --git a/erpnext/patches/v11_0/move_leave_approvers_from_employee.py b/erpnext/patches/v11_0/move_leave_approvers_from_employee.py index 2cd2362fae..af324f2d48 100644 --- a/erpnext/patches/v11_0/move_leave_approvers_from_employee.py +++ b/erpnext/patches/v11_0/move_leave_approvers_from_employee.py @@ -1,18 +1,30 @@ import frappe from frappe import _ +from frappe.model.utils.rename_field import rename_field def execute(): frappe.reload_doc("hr", "doctype", "department_approver") frappe.reload_doc("hr", "doctype", "employee") frappe.reload_doc("hr", "doctype", "department") + if frappe.db.has_column('Department', 'leave_approver'): + rename_field('Department', "leave_approver", "leave_approvers") + + if frappe.db.has_column('Department', 'expense_approver'): + rename_field('Department', "expense_approver", "expense_approvers") + approvers = frappe.db.sql("""select distinct app.leave_approver, emp.department from `tabEmployee Leave Approver` app, `tabEmployee` emp where app.parenttype = 'Employee' and emp.name = app.parent """, as_dict=True) + for record in approvers: if record.department: - frappe.db.sql("""update `tabDepartment Approver` set parenttype = '{0}', - parent = '{1}' and parentfield = 'leave_approver' where approver = '{2}'""" - .format(_('Department'), record.department, record.leave_approver)) + department = frappe.get_doc("Department", record.department) + if not department: + return + if not len(department.leave_approvers): + department.append("leave_approvers",{ + "approver": record.leave_approver + }).db_insert() \ No newline at end of file