diff --git a/geolocation/doc_events/employee_checkin.py b/geolocation/doc_events/employee_checkin.py new file mode 100644 index 0000000..eccbff0 --- /dev/null +++ b/geolocation/doc_events/employee_checkin.py @@ -0,0 +1,19 @@ +import frappe +import json +import requests + +def validate(doc, methods=None): + doc.latitude = 9.968577 + doc.longitude = 76.303978 + if doc.latitude and doc.longitude and not doc.custom_location: + url = "https://nominatim.openstreetmap.org/reverse?lat={lat}&lon={lon}&format=json".format( + lat = doc.latitude, + lon = doc.longitude + ) + response = requests.get(url) + if response.status_code == 200: + response = response.json() + doc.custom_location = str(response.get("display_name")) + else: + doc.custom_location = "" + \ No newline at end of file diff --git a/geolocation/fixtures/custom_field.json b/geolocation/fixtures/custom_field.json new file mode 100644 index 0000000..e3652d1 --- /dev/null +++ b/geolocation/fixtures/custom_field.json @@ -0,0 +1,58 @@ +[ + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Employee Checkin", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_location", + "fieldtype": "Small Text", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "attendance", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Location", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2024-06-12 11:03:55.148981", + "module": null, + "name": "Employee Checkin-custom_location", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + } +] \ No newline at end of file diff --git a/geolocation/hooks.py b/geolocation/hooks.py index ccbdfa1..0c3c1d9 100644 --- a/geolocation/hooks.py +++ b/geolocation/hooks.py @@ -122,13 +122,11 @@ # --------------- # Hook on document methods and events -# doc_events = { -# "*": { -# "on_update": "method", -# "on_cancel": "method", -# "on_trash": "method" -# } -# } +doc_events = { + "Employee Checkin": { + "validate": "geolocation.doc_events.employee_checkin.validate" + } +} # Scheduled Tasks # --------------- @@ -227,3 +225,17 @@ # "Logging DocType Name": 30 # days to retain logs # } +fixtures = [ + { + "doctype": "Custom Field", + "filters": [ + [ + "name", + "in", + [ + "Employee Checkin-custom_location" + ] + ] + ] + } +] \ No newline at end of file