feat: Employee level Shift Request Approver
This commit is contained in:
parent
43ba7dd4c8
commit
17e6d0918b
@ -20,7 +20,7 @@ def get_approvers(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
approvers = []
|
approvers = []
|
||||||
department_details = {}
|
department_details = {}
|
||||||
department_list = []
|
department_list = []
|
||||||
employee = frappe.get_value("Employee", filters.get("employee"), ["department", "leave_approver", "expense_approver"], as_dict=True)
|
employee = frappe.get_value("Employee", filters.get("employee"), ["department", "leave_approver", "expense_approver", "shift_request_approver"], as_dict=True)
|
||||||
|
|
||||||
employee_department = filters.get("department") or employee.department
|
employee_department = filters.get("department") or employee.department
|
||||||
if employee_department:
|
if employee_department:
|
||||||
@ -37,6 +37,8 @@ def get_approvers(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
if filters.get("doctype") == "Expense Claim" and employee.expense_approver:
|
if filters.get("doctype") == "Expense Claim" and employee.expense_approver:
|
||||||
approvers.append(frappe.db.get_value("User", employee.expense_approver, ['name', 'first_name', 'last_name']))
|
approvers.append(frappe.db.get_value("User", employee.expense_approver, ['name', 'first_name', 'last_name']))
|
||||||
|
|
||||||
|
if filters.get("doctype") == "Shift Request" and employee.shift_request_approver:
|
||||||
|
approvers.append(frappe.db.get_value("User", employee.shift_request_approver, ['name', 'first_name', 'last_name']))
|
||||||
|
|
||||||
if filters.get("doctype") == "Leave Application":
|
if filters.get("doctype") == "Leave Application":
|
||||||
parentfield = "leave_approvers"
|
parentfield = "leave_approvers"
|
||||||
|
@ -51,10 +51,14 @@
|
|||||||
"column_break_31",
|
"column_break_31",
|
||||||
"grade",
|
"grade",
|
||||||
"branch",
|
"branch",
|
||||||
|
"approvers_section",
|
||||||
|
"expense_approver",
|
||||||
|
"leave_approver",
|
||||||
|
"column_break_45",
|
||||||
|
"shift_request_approver",
|
||||||
"attendance_and_leave_details",
|
"attendance_and_leave_details",
|
||||||
"leave_policy",
|
"leave_policy",
|
||||||
"attendance_device_id",
|
"attendance_device_id",
|
||||||
"leave_approver",
|
|
||||||
"column_break_44",
|
"column_break_44",
|
||||||
"holiday_list",
|
"holiday_list",
|
||||||
"default_shift",
|
"default_shift",
|
||||||
@ -62,7 +66,6 @@
|
|||||||
"salary_mode",
|
"salary_mode",
|
||||||
"payroll_cost_center",
|
"payroll_cost_center",
|
||||||
"column_break_52",
|
"column_break_52",
|
||||||
"expense_approver",
|
|
||||||
"bank_name",
|
"bank_name",
|
||||||
"bank_ac_no",
|
"bank_ac_no",
|
||||||
"health_insurance_section",
|
"health_insurance_section",
|
||||||
@ -806,14 +809,37 @@
|
|||||||
"fieldname": "expense_approver",
|
"fieldname": "expense_approver",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Expense Approver",
|
"label": "Expense Approver",
|
||||||
"options": "User"
|
"options": "User",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "approvers_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Approvers",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_45",
|
||||||
|
"fieldtype": "Column Break",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "shift_request_approver",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Shift Request Approver",
|
||||||
|
"options": "User",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-user",
|
"icon": "fa fa-user",
|
||||||
"idx": 24,
|
"idx": 24,
|
||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-07-03 21:28:04.109189",
|
"modified": "2020-07-28 01:36:04.109189",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Employee",
|
"name": "Employee",
|
||||||
|
@ -97,8 +97,6 @@ def add_assignments(events, start, end, conditions=None):
|
|||||||
query += conditions
|
query += conditions
|
||||||
|
|
||||||
for d in frappe.db.sql(query, {"start_date":start}, as_dict=True):
|
for d in frappe.db.sql(query, {"start_date":start}, as_dict=True):
|
||||||
from pprint import pprint
|
|
||||||
pprint(d)
|
|
||||||
e = {
|
e = {
|
||||||
"name": d.name,
|
"name": d.name,
|
||||||
"doctype": "Shift Assignment",
|
"doctype": "Shift Assignment",
|
||||||
@ -155,13 +153,16 @@ def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=Fals
|
|||||||
direction = '<' if next_shift_direction == 'reverse' else '>'
|
direction = '<' if next_shift_direction == 'reverse' else '>'
|
||||||
sort_order = 'desc' if next_shift_direction == 'reverse' else 'asc'
|
sort_order = 'desc' if next_shift_direction == 'reverse' else 'asc'
|
||||||
dates = frappe.db.get_all('Shift Assignment',
|
dates = frappe.db.get_all('Shift Assignment',
|
||||||
'start_date',
|
['start_date', 'end_date'],
|
||||||
{'employee':employee, 'start_date':(direction, for_date), 'docstatus': '1', "status": "Active"},
|
{'employee':employee, 'start_date':(direction, for_date), 'docstatus': '1', "status": "Active"},
|
||||||
as_list=True,
|
as_list=True,
|
||||||
limit=MAX_DAYS, order_by="date "+sort_order)
|
limit=MAX_DAYS, order_by="start_date "+sort_order)
|
||||||
|
|
||||||
|
if dates:
|
||||||
for date in dates:
|
for date in dates:
|
||||||
shift_details = get_employee_shift(employee, date.start_date, consider_default_shift, None)
|
if date[1] and date[1] < for_date:
|
||||||
|
continue
|
||||||
|
shift_details = get_employee_shift(employee, date[0], consider_default_shift, None)
|
||||||
if shift_details:
|
if shift_details:
|
||||||
shift_type_name = shift_details.shift_type.name
|
shift_type_name = shift_details.shift_type.name
|
||||||
for_date = date[0]
|
for_date = date[0]
|
||||||
|
@ -7,7 +7,6 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import formatdate, getdate
|
from frappe.utils import formatdate, getdate
|
||||||
from erpnext.hr.doctype.department_approver.department_approver import get_approvers
|
|
||||||
|
|
||||||
class OverlapError(frappe.ValidationError): pass
|
class OverlapError(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ class ShiftRequest(Document):
|
|||||||
approvers = [approver[0] for approver in approvers]
|
approvers = [approver[0] for approver in approvers]
|
||||||
approvers.append(shift_approver)
|
approvers.append(shift_approver)
|
||||||
if self.approver not in approvers:
|
if self.approver not in approvers:
|
||||||
frappe.throw(__("Only Approvers can Approve this Request."))
|
frappe.throw(_("Only Approvers can Approve this Request."))
|
||||||
|
|
||||||
def validate_dates(self):
|
def validate_dates(self):
|
||||||
if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)):
|
if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user