2018-01-15 13:07:39 +00:00
|
|
|
# Copyright (c) 2017, Frappe and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
|
|
|
|
|
|
|
def execute():
|
2018-02-12 10:32:57 +00:00
|
|
|
if frappe.db.a_row_exists("Leave Application"):
|
|
|
|
frappe.reload_doc("hr", "doctype", "leave_application")
|
|
|
|
frappe.reload_doc("workflow", "doctype", "workflow")
|
2018-05-16 05:50:30 +00:00
|
|
|
states = {"Approved": "Success", "Rejected": "Danger", "Open": "Warning"}
|
2018-02-12 10:32:57 +00:00
|
|
|
|
|
|
|
for state, style in states.items():
|
|
|
|
if not frappe.db.exists("Workflow State", state):
|
|
|
|
frappe.get_doc({
|
2018-05-16 05:50:30 +00:00
|
|
|
"doctype": "Workflow State",
|
|
|
|
"workflow_state_name": state,
|
|
|
|
"style": style
|
2018-02-12 10:32:57 +00:00
|
|
|
}).insert(ignore_permissions=True)
|
|
|
|
|
2018-05-16 05:50:30 +00:00
|
|
|
for action in ["Approve", "Reject"]:
|
2018-02-12 10:32:57 +00:00
|
|
|
if not frappe.db.exists("Workflow Action", action):
|
|
|
|
frappe.get_doc({
|
2018-05-16 05:50:30 +00:00
|
|
|
"doctype": "Workflow Action",
|
|
|
|
"workflow_action_name": action
|
2018-02-12 10:32:57 +00:00
|
|
|
}).insert(ignore_permissions=True)
|
|
|
|
|
|
|
|
if not frappe.db.exists("Workflow", "Leave Approval"):
|
|
|
|
frappe.get_doc({
|
2018-05-16 05:50:30 +00:00
|
|
|
"doctype": "Workflow",
|
|
|
|
"workflow_name": "Leave Approval",
|
|
|
|
"document_type": "Leave Application",
|
|
|
|
"is_active": 1,
|
|
|
|
"workflow_state_field": "workflow_state",
|
|
|
|
"states": [{
|
|
|
|
"state": "Open",
|
2018-02-12 10:32:57 +00:00
|
|
|
"doc_status": 0,
|
2018-05-16 05:50:30 +00:00
|
|
|
"update_field": "status",
|
|
|
|
"update_value": "Open",
|
|
|
|
"allow_edit": "Employee"
|
2018-02-12 10:32:57 +00:00
|
|
|
}, {
|
2018-05-16 05:50:30 +00:00
|
|
|
"state": "Approved",
|
2018-02-12 10:32:57 +00:00
|
|
|
"doc_status": 1,
|
2018-05-16 05:50:30 +00:00
|
|
|
"update_field": "status",
|
|
|
|
"update_value": "Approved",
|
|
|
|
"allow_edit": "Leave Approver"
|
2018-02-12 10:32:57 +00:00
|
|
|
}, {
|
2018-05-16 05:50:30 +00:00
|
|
|
"state": "Rejected",
|
2018-02-12 10:32:57 +00:00
|
|
|
"doc_status": 0,
|
2018-05-16 05:50:30 +00:00
|
|
|
"update_field": "status",
|
|
|
|
"update_value": "Rejected",
|
|
|
|
"allow_edit": "Leave Approver"
|
2018-02-12 10:32:57 +00:00
|
|
|
}],
|
2018-05-16 05:50:30 +00:00
|
|
|
"transitions": [{
|
|
|
|
"state": "Open",
|
|
|
|
"action": "Approve",
|
|
|
|
"next_state": "Approved",
|
|
|
|
"allowed": "Leave Approver"
|
2018-02-12 10:32:57 +00:00
|
|
|
},
|
|
|
|
{
|
2018-05-16 05:50:30 +00:00
|
|
|
"state": "Open",
|
|
|
|
"action": "Reject",
|
|
|
|
"next_state": "Rejected",
|
|
|
|
"allowed": "Leave Approver"
|
2018-02-12 10:32:57 +00:00
|
|
|
}]
|
|
|
|
}).insert(ignore_permissions=True)
|
|
|
|
|
|
|
|
if frappe.db.has_column("Leave Application", "status"):
|
|
|
|
frappe.db.sql("""update `tabLeave Application` set workflow_state = status""")
|
|
|
|
|
|
|
|
if frappe.db.has_column("Leave Application", "workflow_state"):
|
|
|
|
frappe.db.sql("""update `tabWorkflow Document State` set doc_status = 0 where parent = "Leave Approval" \
|
|
|
|
and state = "Rejected" and doc_status = 1""")
|
|
|
|
frappe.db.sql("""update `tabLeave Application` set docstatus = 0 where workflow_state = "Rejected" and docstatus = 1""")
|