This commit is contained in:
gsinghpal
2026-03-01 14:42:49 -05:00
parent b925766966
commit a3e85a23ef
28 changed files with 2283 additions and 195 deletions

View File

@@ -57,29 +57,34 @@ class FusionClockAPI(http.Controller):
if not locations:
return False, 0, 'no_locations', 'gps'
gps_available = latitude != 0 or longitude != 0
geocoded = locations.filtered(lambda l: l.latitude and l.longitude
and not (l.latitude == 0.0 and l.longitude == 0.0))
if not geocoded:
return False, 0, 'no_geocoded', 'gps'
nearest_location = False
nearest_distance = float('inf')
for loc in geocoded:
dist = haversine_distance(latitude, longitude, loc.latitude, loc.longitude)
if dist <= loc.radius:
return loc, dist, None, 'gps'
if dist < nearest_distance:
nearest_distance = dist
nearest_location = loc
if gps_available and geocoded:
for loc in geocoded:
dist = haversine_distance(latitude, longitude, loc.latitude, loc.longitude)
if dist <= loc.radius:
return loc, dist, None, 'gps'
if dist < nearest_distance:
nearest_distance = dist
# IP fallback check
# IP fallback -- try when GPS is unavailable OR GPS is outside all geofences
ICP = request.env['ir.config_parameter'].sudo()
if ICP.get_param('fusion_clock.enable_ip_fallback', 'False') == 'True' and client_ip:
if client_ip:
for loc in locations:
if loc.check_ip_whitelist(client_ip):
return loc, 0, None, 'ip'
if not gps_available:
return False, 0, 'gps_unavailable', 'gps'
if not geocoded:
return False, 0, 'no_geocoded', 'gps'
return False, nearest_distance, 'outside', 'gps'
def _location_error_message(self, error_type, distance=0):
@@ -87,6 +92,8 @@ class FusionClockAPI(http.Controller):
return 'No clock locations configured. Ask your manager to set up locations in Fusion Clock > Locations.'
elif error_type == 'no_geocoded':
return 'Clock locations exist but have no GPS coordinates. Ask your manager to geocode them.'
elif error_type == 'gps_unavailable':
return 'Could not determine your location. Please enable GPS/location services in your browser and device settings, then try again.'
else:
dist_str = f"{int(distance)}m" if distance < 1000 else f"{distance/1000:.1f}km"
return f'You are {dist_str} away from the nearest clock location. Please clock in/out within the allowed area.'