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

@@ -125,6 +125,53 @@ class FusionClockLocation(models.Model):
return False
return False
def action_detect_ip(self):
"""Detect the current public IP and append it to the whitelist."""
self.ensure_one()
try:
resp = requests.get('https://ipapi.co/json/', timeout=10)
data = resp.json()
ip = data.get('ip', '')
if not ip:
raise UserError(_("Could not detect public IP."))
except requests.exceptions.RequestException as e:
raise UserError(_("Network error detecting IP: %s") % str(e))
existing = (self.ip_whitelist or '').strip()
existing_lines = [l.strip() for l in existing.split('\n') if l.strip()] if existing else []
if ip in existing_lines:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('Already Whitelisted'),
'message': _('%s is already in the whitelist.') % ip,
'type': 'warning',
'sticky': False,
},
}
existing_lines.append(ip)
self.ip_whitelist = '\n'.join(existing_lines)
city = data.get('city', '')
org = data.get('org', '')
detail = f"{ip}"
if city:
detail += f" ({city}"
if org:
detail += f" - {org}"
detail += ")"
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('IP Detected & Added'),
'message': _('Added %s to the whitelist.') % detail,
'type': 'success',
'sticky': False,
},
}
def action_geocode_address(self):
"""Geocode the address to get lat/lng using Google Geocoding API.
Falls back to Nominatim (OpenStreetMap) if Google fails.