Difference in Date Time Fields in case of Importing and Manual Data Entry

Hi,

I have some custom code running where I am validating attendance, now I have some datetime fields for attendance doctype. The problem is that when I am importing the attendance via Data Import tool, then the system is considering the data entered as datetime whereas when I enter the data manually in the form the server is getting a unicode.

Here is code for validating which is causing problem

https://github.com/adityaduggal/rigpl-erpnext/blob/hr/rigpl_erpnext/rigpl_erpnext/validations/attendance.py#L14

and

https://github.com/adityaduggal/rigpl-erpnext/blob/hr/rigpl_erpnext/rigpl_erpnext/validations/attendance.py#L82-L84

Now if I convert the datetime fields via datetime.strptime then the import via data import fails since the field are considered as datetime and we cannot convert datetime via this command. Now if I remove the datetime.strptime converstion then the manual entry on the form would give me an error like

TypeError: can't compare datetime.date to unicode

Can anyone help me as to how to remove this ambiguity in the system or is there a trick during import that I am missing.

Hi Aditya,

Instead of using datetime convert Unicode to datetime (which will also break if you change the time format), use the getdate method in frappe.utils and use it like so :

from frape.utils import getdate

date = getdate(doc.att_date)

This should solve your problem

3 Likes

Thanks it works perfectly.

1 Like