From 4a6694e80afed88502086a80ed581444c846f6f1 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Wed, 11 Aug 2021 12:59:22 +0530 Subject: [PATCH] fix: changes requested --- erpnext/hr/doctype/attendance/attendance.js | 4 +- erpnext/hr/doctype/attendance/attendance.json | 20 +++++----- erpnext/hr/doctype/attendance/attendance.py | 21 +++++----- erpnext/hr/doctype/shift_type/shift_type.json | 25 +++++++++++- erpnext/hr/doctype/shift_type/shift_type.py | 9 +++-- .../shift_type/shift_type_dashboard.py | 19 --------- .../doctype/overtime_slip/overtime_slip.js | 22 +++++------ .../doctype/overtime_slip/overtime_slip.json | 18 ++++++--- .../doctype/overtime_slip/overtime_slip.py | 39 ++++++++++--------- .../doctype/overtime_type/overtime_type.json | 17 +++++++- .../overtime_type/overtime_type_dashboard.py | 15 ------- .../payroll_settings/payroll_settings.json | 4 +- 12 files changed, 110 insertions(+), 103 deletions(-) delete mode 100644 erpnext/hr/doctype/shift_type/shift_type_dashboard.py delete mode 100644 erpnext/payroll/doctype/overtime_type/overtime_type_dashboard.py diff --git a/erpnext/hr/doctype/attendance/attendance.js b/erpnext/hr/doctype/attendance/attendance.js index ee83e8d90af..0ca9a137f4b 100644 --- a/erpnext/hr/doctype/attendance/attendance.js +++ b/erpnext/hr/doctype/attendance/attendance.js @@ -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" }; diff --git a/erpnext/hr/doctype/attendance/attendance.json b/erpnext/hr/doctype/attendance/attendance.json index a0a9584cc93..6a5397d9bf1 100644 --- a/erpnext/hr/doctype/attendance/attendance.json +++ b/erpnext/hr/doctype/attendance/attendance.json @@ -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", diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py index 2a1239756ba..d48f9800a3b 100644 --- a/erpnext/hr/doctype/attendance/attendance.py +++ b/erpnext/hr/doctype/attendance/attendance.py @@ -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}, diff --git a/erpnext/hr/doctype/shift_type/shift_type.json b/erpnext/hr/doctype/shift_type/shift_type.json index 23935511cee..377aea3859a 100644 --- a/erpnext/hr/doctype/shift_type/shift_type.json +++ b/erpnext/hr/doctype/shift_type/shift_type.json @@ -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", diff --git a/erpnext/hr/doctype/shift_type/shift_type.py b/erpnext/hr/doctype/shift_type/shift_type.py index 294f52199c5..c899def26a2 100644 --- a/erpnext/hr/doctype/shift_type/shift_type.py +++ b/erpnext/hr/doctype/shift_type/shift_type.py @@ -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): diff --git a/erpnext/hr/doctype/shift_type/shift_type_dashboard.py b/erpnext/hr/doctype/shift_type/shift_type_dashboard.py deleted file mode 100644 index c9d2286b6b6..00000000000 --- a/erpnext/hr/doctype/shift_type/shift_type_dashboard.py +++ /dev/null @@ -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'] - } - ] - } diff --git a/erpnext/payroll/doctype/overtime_slip/overtime_slip.js b/erpnext/payroll/doctype/overtime_slip/overtime_slip.js index df549f67858..0f8cae192ec 100644 --- a/erpnext/payroll/doctype/overtime_slip/overtime_slip.js +++ b/erpnext/payroll/doctype/overtime_slip/overtime_slip.js @@ -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) { diff --git a/erpnext/payroll/doctype/overtime_slip/overtime_slip.json b/erpnext/payroll/doctype/overtime_slip/overtime_slip.json index fcbfdc96f5f..bca8e0f4e09 100644 --- a/erpnext/payroll/doctype/overtime_slip/overtime_slip.json +++ b/erpnext/payroll/doctype/overtime_slip/overtime_slip.json @@ -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 } \ No newline at end of file diff --git a/erpnext/payroll/doctype/overtime_slip/overtime_slip.py b/erpnext/payroll/doctype/overtime_slip/overtime_slip.py index 0b99114b4ec..6f1412144d1 100644 --- a/erpnext/payroll/doctype/overtime_slip/overtime_slip.py +++ b/erpnext/payroll/doctype/overtime_slip/overtime_slip.py @@ -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)) - diff --git a/erpnext/payroll/doctype/overtime_type/overtime_type.json b/erpnext/payroll/doctype/overtime_type/overtime_type.json index a04c1a7f193..e33881547a5 100644 --- a/erpnext/payroll/doctype/overtime_type/overtime_type.json +++ b/erpnext/payroll/doctype/overtime_type/overtime_type.json @@ -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", diff --git a/erpnext/payroll/doctype/overtime_type/overtime_type_dashboard.py b/erpnext/payroll/doctype/overtime_type/overtime_type_dashboard.py deleted file mode 100644 index de42f395b03..00000000000 --- a/erpnext/payroll/doctype/overtime_type/overtime_type_dashboard.py +++ /dev/null @@ -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')] - } - ] - } \ No newline at end of file diff --git a/erpnext/payroll/doctype/payroll_settings/payroll_settings.json b/erpnext/payroll/doctype/payroll_settings/payroll_settings.json index 45b182325e6..f056fe2ec7e 100644 --- a/erpnext/payroll/doctype/payroll_settings/payroll_settings.json +++ b/erpnext/payroll/doctype/payroll_settings/payroll_settings.json @@ -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",