How To: Stop auto attendance from marking absent

We have been using ERPNext integrated with biometric sensor. While the integration works great for auto-marking attendance its an annoyance when the employee gets marked as absent by auto-attendance because absents are different from leaves and it throws the whole leave calculation haywire. There is a background that the system does not know which kind of leave to use in place of attendance hence it marks them absent. So the solution to this problem is not very simple or universal.

For our requirements to make it simple, below is a code snip that we use to stop auto attendance from marking as absent. Then HR manually ensures that correct leave is applied for the missing date. Lots of users have faced similar issues on this forum hence I decided to post the code snip, so it may help others.

We have a custom app which has all the customizations for out ERPNext instance. We are self-hosted using version 15 of ERPNext.

in hooks.py of the customization project the document Shift Type is overridden, this should work for v13 upwards. Note there is a space in the document name “Shift Type” if you don’t put the space this will not work!

# DocType Class
# ---------------
# Override standard doctype classes

override_doctype_class = {
	"Shift Type": "mycustomization.mycustomization.shift_type.CustomShiftType"
 }

Then in the custom project mycustomization folder there is a shift_type.py file created. It has the following code.

shift_type.py

import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import cint, get_datetime
from hrms.hr.doctype.shift_type.shift_type import ShiftType

class CustomShiftType(ShiftType):
	
	
	def mark_absent_for_dates_with_no_attendance(self, employee: str):
		# Custom code if you want to apply for leave yourself. 
		pass

The method mark_absent_for_dates_with_no_attendance from the Shift Type document is being override in the hooks.py to do nothing. Hence no absents are marked. You can modify the codebase to auto-add new leave type for that employee based on your company requirements.

I hope this small snip is helpful to others struggling with this issue.

1 Like