From 367c2e7f327832ffbd5562a71197f6bdb6b3e66e Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 3 Apr 2024 07:27:31 +0530 Subject: [PATCH 01/10] feat: geolocation in Employee Checkin --- .../employee_checkin/employee_checkin.json | 34 +++++++++++++++++-- .../employee_checkin/employee_checkin.py | 14 ++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/hrms/hr/doctype/employee_checkin/employee_checkin.json b/hrms/hr/doctype/employee_checkin/employee_checkin.json index 146254d9e4..cacfb51e3a 100644 --- a/hrms/hr/doctype/employee_checkin/employee_checkin.json +++ b/hrms/hr/doctype/employee_checkin/employee_checkin.json @@ -15,8 +15,13 @@ "device_id", "skip_auto_attendance", "attendance", + "location_section", + "coordinates", + "geolocation", + "shift_timings_section", "shift_start", "shift_end", + "column_break_vyyt", "shift_actual_start", "shift_actual_end" ], @@ -107,10 +112,35 @@ "fieldtype": "Datetime", "hidden": 1, "label": "Shift Actual End" + }, + { + "fieldname": "location_section", + "fieldtype": "Section Break", + "label": "Location" + }, + { + "fieldname": "coordinates", + "fieldtype": "Data", + "label": "Coordinates", + "read_only": 1 + }, + { + "fieldname": "geolocation", + "fieldtype": "Geolocation", + "label": "Geolocation" + }, + { + "fieldname": "shift_timings_section", + "fieldtype": "Section Break", + "label": "Shift Timings" + }, + { + "fieldname": "column_break_vyyt", + "fieldtype": "Column Break" } ], "links": [], - "modified": "2024-04-02 01:50:23.150627", + "modified": "2024-04-03 06:36:07.640893", "modified_by": "Administrator", "module": "HR", "name": "Employee Checkin", @@ -210,4 +240,4 @@ "states": [], "title_field": "employee_name", "track_changes": 1 -} \ No newline at end of file +} diff --git a/hrms/hr/doctype/employee_checkin/employee_checkin.py b/hrms/hr/doctype/employee_checkin/employee_checkin.py index 8524b6ef6a..7a5e784a76 100644 --- a/hrms/hr/doctype/employee_checkin/employee_checkin.py +++ b/hrms/hr/doctype/employee_checkin/employee_checkin.py @@ -18,6 +18,7 @@ def validate(self): validate_active_employee(self.employee) self.validate_duplicate_log() self.fetch_shift() + self.set_geolocation_coordinates() def validate_duplicate_log(self): doc = frappe.db.exists( @@ -60,6 +61,19 @@ def fetch_shift(self): else: self.shift = None + def set_geolocation_coordinates(self): + if not self.geolocation: + return + + try: + self.coordinates = str(get_coordinates_from_geolocation(self.geolocation)) + except Exception: + frappe.log_error("Error parsing geolocation field") + + +def get_coordinates_from_geolocation(geolocation: str): + return frappe.parse_json(geolocation)["features"][0]["geometry"]["coordinates"] + @frappe.whitelist() def add_log_based_on_employee_field( From 56dca0511344b519c9d2eb6af87dcdb624a83b54 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 3 Apr 2024 07:29:07 +0530 Subject: [PATCH 02/10] feat(PWA): capture geolocation in checkins --- frontend/src/components/CheckInPanel.vue | 59 ++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/CheckInPanel.vue b/frontend/src/components/CheckInPanel.vue index 99481e03e8..80dfcc59c9 100644 --- a/frontend/src/components/CheckInPanel.vue +++ b/frontend/src/components/CheckInPanel.vue @@ -9,7 +9,7 @@