Attendance request for future dates

Hello everyone,
I am trying to implement attendance and have encountered a niggle. In my company, some staff go for fieldwork for about 2 months and it would be impractical to only mark attendance retrospectively. I would like to be able to mark attendance for future dates, similar to how leave applications can mark attendance for future dates. Although I am still learning the ropes with Python, I have singled out the line that is throwing the error.

           if self.status != 'On Leave' and not self.leave_application and getdate(self.attendance_date) > getdate(nowdate()):                                                                                               
                    frappe.throw(_("Attendance can not be marked for future dates"))                                                                                                       

Can I go ahead and comment this out? Is there a better way to achieve this?
Thank you!

On my test environment, commenting out the validation works. However, on the attendance request doctype, I can’t find the line throwing the error “Future dates not allowed”. I have checked both the .py and .js file extensively. Please I need help :sob: :sob:

Hey @Syd This is coming from ‘validate_dates’ method in apps/erpnext/erpnext/hr/utils.py

Thank you very much. What do you think of my approach with this? Is there a better way to do this?

Commenting or editing code in erpnext/frappe is not good practise, you can’t upgrade your versions in future

best approach is you can create custom app and override validate method in attendance request

I actually have a custom app, how would I create my own validation to replace the existing one?

Please show me how to do this. Or send me some links I can read. I’ll start digging around for something myself

This may be help full for you
https://github.com/frappe/frappe/pull/11527

Thank you @abrarpv97,
I was able to override the class of the attendance doctype. However, the method “validate_dates” does not belong to a class and I have not found a way to override that. Can you point me in the right direction, please?

@Syd you can override validate method of attenedance request

I tried this. Before overriding, I was not able to save future dates. After overriding, I was able to save future dates but the error came on again when I tried to submit the form. I even tried to directly edit the attendance_request.py to remove the validate method on my test bed but it kept throwing the same error

@Syd while you are submitting attendance , in the backend it will create attendance

So your second error will be from attendance.py (in validate method) , here is the reference

So I had done this already, this was actually my first course of action. I can confirm that it is no more throwing the error. The error is certainly coming from “validate_dates” on the utils.py file. As the function does not belong to a class, I still have not found a way to override it. How do I override the function?

Another problem I have encountered, I have to stop the system from marking attendance as absent (I would like it to continue to mark as present hourly as it is doing) until a certain day (25th of every month by 10pm, I can create a cron job to do this). I have looked though attendance.py and shift.py and it seems the function (mark_absent_for_dates_with_no_attendance) is the only function that I have to override. How can I go about it?