feat(UX): Option to exclude holidays while marking monthly attendance (#29185)
This commit is contained in:
parent
6bea91e9fe
commit
6aac8de53e
@ -5,9 +5,9 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
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):
|
class Attendance(Document):
|
||||||
@ -171,7 +171,7 @@ def get_month_map():
|
|||||||
})
|
})
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_unmarked_days(employee, month):
|
def get_unmarked_days(employee, month, exclude_holidays=0):
|
||||||
import calendar
|
import calendar
|
||||||
month_map = get_month_map()
|
month_map = get_month_map()
|
||||||
|
|
||||||
@ -191,6 +191,11 @@ def get_unmarked_days(employee, month):
|
|||||||
])
|
])
|
||||||
|
|
||||||
marked_days = [get_datetime(record.attendance_date) for record in records]
|
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 = []
|
unmarked_days = []
|
||||||
|
|
||||||
for date in dates_of_month:
|
for date in dates_of_month:
|
||||||
|
@ -28,6 +28,7 @@ frappe.listview_settings['Attendance'] = {
|
|||||||
onchange: function() {
|
onchange: function() {
|
||||||
dialog.set_df_property("unmarked_days", "hidden", 1);
|
dialog.set_df_property("unmarked_days", "hidden", 1);
|
||||||
dialog.set_df_property("status", "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("month", "value", '');
|
||||||
dialog.set_df_property("unmarked_days", "options", []);
|
dialog.set_df_property("unmarked_days", "options", []);
|
||||||
dialog.no_unmarked_days_left = false;
|
dialog.no_unmarked_days_left = false;
|
||||||
@ -42,9 +43,14 @@ frappe.listview_settings['Attendance'] = {
|
|||||||
onchange: function() {
|
onchange: function() {
|
||||||
if (dialog.fields_dict.employee.value && dialog.fields_dict.month.value) {
|
if (dialog.fields_dict.employee.value && dialog.fields_dict.month.value) {
|
||||||
dialog.set_df_property("status", "hidden", 0);
|
dialog.set_df_property("status", "hidden", 0);
|
||||||
|
dialog.set_df_property("exclude_holidays", "hidden", 0);
|
||||||
dialog.set_df_property("unmarked_days", "options", []);
|
dialog.set_df_property("unmarked_days", "options", []);
|
||||||
dialog.no_unmarked_days_left = false;
|
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) {
|
if (options.length > 0) {
|
||||||
dialog.set_df_property("unmarked_days", "hidden", 0);
|
dialog.set_df_property("unmarked_days", "hidden", 0);
|
||||||
dialog.set_df_property("unmarked_days", "options", options);
|
dialog.set_df_property("unmarked_days", "options", options);
|
||||||
@ -64,6 +70,31 @@ frappe.listview_settings['Attendance'] = {
|
|||||||
reqd: 1,
|
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"),
|
label: __("Unmarked Attendance for days"),
|
||||||
fieldname: "unmarked_days",
|
fieldname: "unmarked_days",
|
||||||
@ -105,7 +136,7 @@ frappe.listview_settings['Attendance'] = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
get_multi_select_options: function(employee, month) {
|
get_multi_select_options: function(employee, month, exclude_holidays) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: 'erpnext.hr.doctype.attendance.attendance.get_unmarked_days',
|
method: 'erpnext.hr.doctype.attendance.attendance.get_unmarked_days',
|
||||||
@ -113,6 +144,7 @@ frappe.listview_settings['Attendance'] = {
|
|||||||
args: {
|
args: {
|
||||||
employee: employee,
|
employee: employee,
|
||||||
month: month,
|
month: month,
|
||||||
|
exclude_holidays: exclude_holidays
|
||||||
}
|
}
|
||||||
}).then(r => {
|
}).then(r => {
|
||||||
var options = [];
|
var options = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user