fix: changes requested

This commit is contained in:
Anurag Mishra
2021-08-11 12:59:22 +05:30
parent 8db493b2be
commit 4a6694e80a
12 changed files with 110 additions and 103 deletions

View File

@@ -12,10 +12,10 @@ frappe.ui.form.on('Attendance', {
});
if (frm.doc.__islocal) {
cur_frm.set_value("attendance_date", frappe.datetime.get_today());
frm.set_value("attendance_date", frappe.datetime.get_today());
}
frm.set_query("employee", ()=>{
frm.set_query("employee", () => {
return {
query: "erpnext.controllers.queries.employee_query"
};

View File

@@ -24,7 +24,7 @@
"in_time",
"out_time",
"column_break_18",
"standard_working_time",
"shift_duration",
"working_time",
"late_entry",
"early_exit",
@@ -208,14 +208,6 @@
"options": "Overtime Type",
"read_only": 1
},
{
"description": "Shift duration for a day",
"fetch_from": "shift.standard_working_time",
"fieldname": "standard_working_time",
"fieldtype": "Duration",
"label": " Standard Working Time",
"read_only": 1
},
{
"depends_on": "working_time",
"fieldname": "working_time",
@@ -240,13 +232,21 @@
{
"fieldname": "column_break_27",
"fieldtype": "Column Break"
},
{
"description": "Shift duration for a day",
"fetch_from": "shift.standard_working_time",
"fieldname": "shift_duration",
"fieldtype": "Duration",
"label": "Shift Duration",
"read_only": 1
}
],
"icon": "fa fa-ok",
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2021-06-09 13:42:36.176547",
"modified": "2021-08-11 11:55:50.076043",
"modified_by": "Administrator",
"module": "HR",
"name": "Attendance",

View File

@@ -22,7 +22,7 @@ class Attendance(Document):
self.set_default_shift()
if not frappe.db.get_single_value("Payroll Settings", "fetch_standard_working_hours_from_shift_type"):
self.standard_working_time = None
self.shift_duration = None
def validate_attendance_date(self):
date_of_joining = frappe.db.get_value("Employee", self.employee, "date_of_joining")
@@ -107,19 +107,17 @@ class Attendance(Document):
#this method is only for Calculation of overtime based on Attendance through Employee Checkins
self.overtime_duration = None
if not self.standard_working_time and self.shift:
self.standard_working_time = frappe.db.get_value("Shift Type", self.shift, "standard_working_time")
if not self.shift_duration and self.shift:
self.shift_duration = frappe.db.get_value("Shift Type", self.shift, "shift_duration")
if not self.overtime_type:
self.overtime_type = get_overtime_type(self.employee)
if int(self.working_time) > int(self.standard_working_time):
self.overtime_duration = int(self.working_time) - int(self.standard_working_time)
if int(self.working_time) > int(self.shift_duration):
self.overtime_duration = int(self.working_time) - int(self.shift_duration)
@frappe.whitelist()
def get_shift_type(employee, attendance_date):
emp_shift = frappe.db.get_value("Employee", employee, "default_shift")
shift_assignment = frappe.db.sql('''SELECT name, shift_type
FROM
`tabShift Assignment`
@@ -136,21 +134,22 @@ def get_shift_type(employee, attendance_date):
if len(shift_assignment):
shift = shift_assignment[0].shift_type
else:
shift = emp_shift
shift = frappe.db.get_value("Employee", employee, "default_shift")
return shift
@frappe.whitelist()
def get_overtime_type(employee):
overtime_type = None
emp_department = frappe.db.get_value("Employee", employee, "department")
emp_details = frappe.db.get_value("Employee", employee, ["department", "grade"], as_dict=1)
emp_department = emp_details.department
if emp_department:
overtime_type_doc = frappe.get_list("Overtime Type", filters={
"applicable_for": "Department", "department": emp_department}, fields=["name"])
if len(overtime_type_doc):
overtime_type = overtime_type_doc[0].name
emp_grade = frappe.db.get_value("Employee", employee, "grade")
emp_grade = emp_details.grade
if emp_grade:
overtime_type_doc = frappe.get_list("Overtime Type", filters={
"applicable_for": "Employee Grade", "employee_grade": emp_grade},

View File

@@ -190,8 +190,29 @@
"label": "Grace Period Settings"
}
],
"links": [],
"modified": "2021-06-15 15:22:55.756078",
"links": [
{
"group": "Attendance and Checkin",
"link_doctype": "Attendance",
"link_fieldname": "shift"
},
{
"group": "Attendance and Checkin",
"link_doctype": "Employee Checkin",
"link_fieldname": "shift"
},
{
"group": "Request and Assignment",
"link_doctype": "Shift Request",
"link_fieldname": "shift_type"
},
{
"group": "Request and Assignment",
"link_doctype": "Shift Assignment",
"link_fieldname": "shift_type"
}
],
"modified": "2021-08-11 12:07:33.227032",
"modified_by": "Administrator",
"module": "HR",
"name": "Shift Type",

View File

@@ -34,11 +34,12 @@ class ShiftType(Document):
self.standard_working_time = convert_time_into_duration(time_difference)
def validate_overtime(self):
if not frappe.db.get_single_value('Payroll Settings', 'fetch_standard_working_hours_from_shift_type') and self.allow_overtime:
frappe.throw(_('Please enable "Fetch Standard Working Hours from Shift Type" in payroll Settings for Overtime.'))
if self.allow_overtime:
if not frappe.db.get_single_value('Payroll Settings', 'fetch_standard_working_hours_from_shift_type'):
frappe.throw(_('Please enable "Fetch Standard Working Hours from Shift Type" in payroll Settings for Overtime.'))
if frappe.db.get_single_value("Payroll Settings", "overtime_based_on") != "Attendance" and self.allow_overtime:
frappe.throw(_('Please set Overtime based on "Attendance" in payroll Settings for Overtime.'))
if frappe.db.get_single_value("Payroll Settings", "overtime_based_on") != "Attendance":
frappe.throw(_('Please set Overtime based on "Attendance" in payroll Settings for Overtime.'))
@frappe.whitelist()
def process_auto_attendance(self):

View File

@@ -1,19 +0,0 @@
from __future__ import unicode_literals
from frappe import _
def get_data():
return {
'fieldname': 'shift',
'non_standard_fieldnames': {
'Shift Request': 'shift_type',
'Shift Assignment': 'shift_type'
},
'transactions': [
{
'items': ['Attendance', 'Employee Checkin']
},
{
'items': ['Shift Request', 'Shift Assignment']
}
]
}

View File

@@ -28,20 +28,16 @@ frappe.ui.form.on('Overtime Slip', {
},
set_frequency_and_dates: function (frm) {
return frappe.call({
method: "erpnext.payroll.doctype.overtime_slip.overtime_slip.get_frequency_and_dates",
args: {
employee: frm.doc.employee,
date: frm.doc.from_date || frm.doc.posting_date,
},
callback: function (r) {
frm.set_value("payroll_frequency", r.message[1]);
if (r.message[0].start_date != frm.doc.from_date) {
frm.set_value("from_date", r.message[0].start_date);
if (frm.doc.employee) {
return frappe.call({
method: 'get_frequency_and_dates',
doc: frm.doc,
callback: function () {
frm.refresh();
}
frm.set_value("to_date", r.message[0].end_date);
}
});
});
}
},
get_emp_details_and_overtime_duration: function (frm) {

View File

@@ -1,11 +1,12 @@
{
"actions": [],
"autoname": "HR-OVR-SLIP-.#####",
"autoname": "HR-OT-SLIP-.#####",
"creation": "2021-05-27 12:47:32.372698",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"employee_details",
"posting_date",
"employee",
"employee_name",
@@ -79,7 +80,6 @@
{
"fieldname": "overtime_details",
"fieldtype": "Table",
"label": "Overtime Details",
"options": "Overtime Details",
"reqd": 1
},
@@ -89,7 +89,8 @@
},
{
"fieldname": "section_break_7",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Payroll Details"
},
{
"fieldname": "from_date",
@@ -123,7 +124,8 @@
},
{
"fieldname": "section_break_12",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Overtime Details"
},
{
"fieldname": "column_break_17",
@@ -143,12 +145,17 @@
"label": "Salary Slip",
"options": "Salary Slip",
"read_only": 1
},
{
"fieldname": "employee_details",
"fieldtype": "Section Break",
"label": "Employee Details"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2021-06-16 14:55:13.441709",
"modified": "2021-08-11 12:30:27.536389",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Overtime Slip",
@@ -192,5 +199,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "employee_name",
"track_changes": 1
}

View File

@@ -10,12 +10,7 @@ from frappe.model.document import Document
class OvertimeSlip(Document):
def validate(self):
if not (self.from_date or self.to_date or self.payroll_frequency):
date = self.from_date or self.posting_date
data = get_frequency_and_dates(self.employee, date)
self.from_date = data[0].start_date
self.to_date = data[0].end_date
self.payroll_frequency = data[1]
self.get_frequency_and_dates()
self.validate_overlap()
if self.from_date >= self.to_date:
@@ -60,7 +55,8 @@ class OvertimeSlip(Document):
if len(records):
self.create_overtime_details_row_for_timesheet(records)
else:
frappe.throw(_('Select "Calculate Overtime Hours Based On" in Payroll Settings'))
link_to_settings = get_link_to_form('Payroll Settings', 'Payroll Settings', 'Payroll Settings')
frappe.throw(_('Select "Calculate Overtime Based On" in {0}').format(link_to_settings))
if len(self.overtime_details):
self.total_overtime_duration = sum([int(detail.overtime_duration) for detail in self.overtime_details])
@@ -145,6 +141,22 @@ class OvertimeSlip(Document):
return records
return []
@frappe.whitelist()
def get_frequency_and_dates(self):
date = self.from_date or self.posting_date
salary_structure = get_salary_structure(self.employee)
if salary_structure:
payroll_frequency = frappe.db.get_value("Salary Structure", salary_structure, "payroll_frequency")
date_details = get_start_end_dates(payroll_frequency, date, frappe.db.get_value('Employee', self.employee, "company"))
self.from_date = date_details.start_date
self.to_date = date_details.end_date
self.payroll_frequency = payroll_frequency
else:
frappe.throw(_("No Salary Structure Assignment found for Employee: {0}").format(self.employee))
@frappe.whitelist()
def get_standard_working_hours(employee, date):
shift_assignment = frappe.db.sql('''SELECT shift_type FROM `tabShift Assignment`
@@ -169,18 +181,9 @@ def get_standard_working_hours(employee, date):
elif not fetch_from_shift:
standard_working_time = frappe.db.get_single_value("HR Settings", "standard_working_hours") * 3600
if not standard_working_time:
frappe.throw(_('Please Set "Standard Working Hours" in HR settings'))
link_to_settings = get_link_to_form('HR Settings', 'HR Settings', 'HR Settings')
frappe.throw(_('Please Set "Standard Working Hours" in {0}').format(link_to_settings))
return standard_working_time
@frappe.whitelist()
def get_frequency_and_dates(employee, date):
salary_structure = get_salary_structure(employee)
if salary_structure:
payroll_frequency = frappe.db.get_value("Salary Structure", salary_structure, "payroll_frequency")
date_details = get_start_end_dates(payroll_frequency, date, frappe.db.get_value('Employee', employee, "company"))
return [date_details, payroll_frequency]
else:
frappe.throw(_("No Salary Structure Assignment found for Employee: {0}").format(employee))

View File

@@ -111,8 +111,21 @@
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-06-15 13:49:20.612464",
"links": [
{
"link_doctype": "Attendance",
"link_fieldname": "overtime_type"
},
{
"link_doctype": "Timesheet",
"link_fieldname": "overtime_type"
},
{
"link_doctype": "Overtime Details",
"link_fieldname": "overtime_type"
}
],
"modified": "2021-08-11 11:29:52.944112",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Overtime Type",

View File

@@ -1,15 +0,0 @@
from __future__ import unicode_literals
from frappe import _
def get_data():
return {
'fieldname': 'overtime_type',
'transactions': [
{
'items': [_('Attendance'), _('Timesheet')]
},
{
'items': [_('Overtime Slip')]
}
]
}

View File

@@ -125,7 +125,7 @@
"default": "Attendance",
"fieldname": "overtime_based_on",
"fieldtype": "Select",
"label": "Calculate Overtime Hours Based On",
"label": "Calculate Overtime Based On",
"options": "Attendance\nTimesheet"
},
{
@@ -139,7 +139,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-06-15 13:55:44.563796",
"modified": "2021-08-11 11:45:10.568381",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Settings",