Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:fetch openstreetmap employee checkin #1

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions geolocation/doc_events/employee_checkin.py
Original file line number Diff line number Diff line change
@@ -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 = ""

58 changes: 58 additions & 0 deletions geolocation/fixtures/custom_field.json
Original file line number Diff line number Diff line change
@@ -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
}
]
26 changes: 19 additions & 7 deletions geolocation/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------
Expand Down Expand Up @@ -227,3 +225,17 @@
# "Logging DocType Name": 30 # days to retain logs
# }

fixtures = [
{
"doctype": "Custom Field",
"filters": [
[
"name",
"in",
[
"Employee Checkin-custom_location"
]
]
]
}
]
Loading