Skip to content

Commit

Permalink
feat(UX): Option to exclude holidays while marking monthly attendance
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Jan 7, 2022
1 parent d28d711 commit 6f6ff67
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
11 changes: 8 additions & 3 deletions erpnext/hr/doctype/attendance/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import cstr, formatdate, get_datetime, getdate, nowdate
from frappe.utils import cint, cstr, formatdate, get_datetime, getdate, nowdate

from erpnext.hr.utils import validate_active_employee
from erpnext.hr.utils import get_holiday_dates_for_employee, validate_active_employee


class Attendance(Document):
Expand Down Expand Up @@ -171,7 +171,7 @@ def get_month_map():
})

@frappe.whitelist()
def get_unmarked_days(employee, month):
def get_unmarked_days(employee, month, exclude_holidays=0):
import calendar
month_map = get_month_map()

Expand All @@ -191,6 +191,11 @@ def get_unmarked_days(employee, month):
])

marked_days = [get_datetime(record.attendance_date) for record in records]
if cint(exclude_holidays):
holiday_dates = get_holiday_dates_for_employee(employee, month_start, month_end)
holidays = [get_datetime(record) for record in holiday_dates]
marked_days.extend(holidays)

unmarked_days = []

for date in dates_of_month:
Expand Down
36 changes: 34 additions & 2 deletions erpnext/hr/doctype/attendance/attendance_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ frappe.listview_settings['Attendance'] = {
onchange: function() {
dialog.set_df_property("unmarked_days", "hidden", 1);
dialog.set_df_property("status", "hidden", 1);
dialog.set_df_property("exclude_holidays", "hidden", 1);
dialog.set_df_property("month", "value", '');
dialog.set_df_property("unmarked_days", "options", []);
dialog.no_unmarked_days_left = false;
Expand All @@ -42,9 +43,14 @@ frappe.listview_settings['Attendance'] = {
onchange: function() {
if (dialog.fields_dict.employee.value && dialog.fields_dict.month.value) {
dialog.set_df_property("status", "hidden", 0);
dialog.set_df_property("exclude_holidays", "hidden", 0);
dialog.set_df_property("unmarked_days", "options", []);
dialog.no_unmarked_days_left = false;
me.get_multi_select_options(dialog.fields_dict.employee.value, dialog.fields_dict.month.value).then(options => {
me.get_multi_select_options(
dialog.fields_dict.employee.value,
dialog.fields_dict.month.value,
dialog.fields_dict.exclude_holidays.get_value()
).then(options => {
if (options.length > 0) {
dialog.set_df_property("unmarked_days", "hidden", 0);
dialog.set_df_property("unmarked_days", "options", options);
Expand All @@ -64,6 +70,31 @@ frappe.listview_settings['Attendance'] = {
reqd: 1,

},
{
label: __("Exclude Holidays"),
fieldtype: "Check",
fieldname: "exclude_holidays",
hidden: 1,
onchange: function() {
if (dialog.fields_dict.employee.value && dialog.fields_dict.month.value) {
dialog.set_df_property("status", "hidden", 0);
dialog.set_df_property("unmarked_days", "options", []);
dialog.no_unmarked_days_left = false;
me.get_multi_select_options(
dialog.fields_dict.employee.value,
dialog.fields_dict.month.value,
dialog.fields_dict.exclude_holidays.get_value()
).then(options => {
if (options.length > 0) {
dialog.set_df_property("unmarked_days", "hidden", 0);
dialog.set_df_property("unmarked_days", "options", options);
} else {
dialog.no_unmarked_days_left = true;
}
});
}
}
},
{
label: __("Unmarked Attendance for days"),
fieldname: "unmarked_days",
Expand Down Expand Up @@ -105,14 +136,15 @@ frappe.listview_settings['Attendance'] = {
});
},

get_multi_select_options: function(employee, month) {
get_multi_select_options: function(employee, month, exclude_holidays) {
return new Promise(resolve => {
frappe.call({
method: 'erpnext.hr.doctype.attendance.attendance.get_unmarked_days',
async: false,
args: {
employee: employee,
month: month,
exclude_holidays: exclude_holidays
}
}).then(r => {
var options = [];
Expand Down

0 comments on commit 6f6ff67

Please sign in to comment.