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 = []
|
||||
department_details = {}
|
||||
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
|
||||
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:
|
||||
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":
|
||||
parentfield = "leave_approvers"
|
||||
|
@ -51,10 +51,14 @@
|
||||
"column_break_31",
|
||||
"grade",
|
||||
"branch",
|
||||
"approvers_section",
|
||||
"expense_approver",
|
||||
"leave_approver",
|
||||
"column_break_45",
|
||||
"shift_request_approver",
|
||||
"attendance_and_leave_details",
|
||||
"leave_policy",
|
||||
"attendance_device_id",
|
||||
"leave_approver",
|
||||
"column_break_44",
|
||||
"holiday_list",
|
||||
"default_shift",
|
||||
@ -62,7 +66,6 @@
|
||||
"salary_mode",
|
||||
"payroll_cost_center",
|
||||
"column_break_52",
|
||||
"expense_approver",
|
||||
"bank_name",
|
||||
"bank_ac_no",
|
||||
"health_insurance_section",
|
||||
@ -806,14 +809,37 @@
|
||||
"fieldname": "expense_approver",
|
||||
"fieldtype": "Link",
|
||||
"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",
|
||||
"idx": 24,
|
||||
"image_field": "image",
|
||||
"links": [],
|
||||
"modified": "2020-07-03 21:28:04.109189",
|
||||
"modified": "2020-07-28 01:36:04.109189",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Employee",
|
||||
|
@ -97,8 +97,6 @@ def add_assignments(events, start, end, conditions=None):
|
||||
query += conditions
|
||||
|
||||
for d in frappe.db.sql(query, {"start_date":start}, as_dict=True):
|
||||
from pprint import pprint
|
||||
pprint(d)
|
||||
e = {
|
||||
"name": d.name,
|
||||
"doctype": "Shift Assignment",
|
||||
@ -155,17 +153,20 @@ def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=Fals
|
||||
direction = '<' if next_shift_direction == 'reverse' else '>'
|
||||
sort_order = 'desc' if next_shift_direction == 'reverse' else 'asc'
|
||||
dates = frappe.db.get_all('Shift Assignment',
|
||||
'start_date',
|
||||
['start_date', 'end_date'],
|
||||
{'employee':employee, 'start_date':(direction, for_date), 'docstatus': '1', "status": "Active"},
|
||||
as_list=True,
|
||||
limit=MAX_DAYS, order_by="date "+sort_order)
|
||||
limit=MAX_DAYS, order_by="start_date "+sort_order)
|
||||
|
||||
for date in dates:
|
||||
shift_details = get_employee_shift(employee, date.start_date, consider_default_shift, None)
|
||||
if shift_details:
|
||||
shift_type_name = shift_details.shift_type.name
|
||||
for_date = date[0]
|
||||
break
|
||||
if dates:
|
||||
for date in dates:
|
||||
if date[1] and date[1] < for_date:
|
||||
continue
|
||||
shift_details = get_employee_shift(employee, date[0], consider_default_shift, None)
|
||||
if shift_details:
|
||||
shift_type_name = shift_details.shift_type.name
|
||||
for_date = date[0]
|
||||
break
|
||||
|
||||
return get_shift_details(shift_type_name, for_date)
|
||||
|
||||
|
@ -7,7 +7,6 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import formatdate, getdate
|
||||
from erpnext.hr.doctype.department_approver.department_approver import get_approvers
|
||||
|
||||
class OverlapError(frappe.ValidationError): pass
|
||||
|
||||
@ -52,7 +51,7 @@ class ShiftRequest(Document):
|
||||
approvers = [approver[0] for approver in approvers]
|
||||
approvers.append(shift_approver)
|
||||
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):
|
||||
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