* Modify patch to move leave approvers from Employee master to Department master

* Rename child table names

- Rename leave approver to leave approvers
- Rename expense approver to expense approvers

* Import cstr

* Fix a condition
This commit is contained in:
Shreya Shah 2018-06-13 17:11:17 +05:30 committed by Nabin Hait
parent aa17294979
commit a2056a39bd
7 changed files with 39 additions and 14 deletions

View File

@ -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",

View File

@ -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

View File

@ -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')

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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()