This commit is contained in:
gsinghpal
2026-04-24 21:04:38 -04:00
parent 0eab4b4efb
commit 41d0908ade
4083 changed files with 1230780 additions and 287 deletions

View File

@@ -55,6 +55,13 @@ class ResConfigSettings(models.TransientModel):
'When set, address geocoding goes to Nominatim instead of Google. '
'Leave empty to use Google.',
)
fc_maps_api_key = fields.Char(
string='FusionMaps API Key',
config_parameter='fusion_tasks.maps_api_key',
help='API key for the FusionMaps gateway at maps.nexasystems.ca. '
'When set, OSRM and Nominatim requests include it as X-API-Key. '
'Leave empty for direct LAN access without authentication.',
)
fc_location_retention_days = fields.Char(
string='Location History Retention (Days)',
config_parameter='fusion_claims.location_retention_days',

View File

@@ -32,12 +32,16 @@ class ResPartner(models.Model):
addr = address.strip()
nominatim_url = (ICP.get_param('fusion_tasks.nominatim_url', '') or '').strip()
if nominatim_url:
headers = {'User-Agent': 'fusion_tasks/1.0'}
maps_key = (ICP.get_param('fusion_tasks.maps_api_key', '') or '').strip()
if maps_key:
headers['X-API-Key'] = maps_key
try:
resp = requests.get(
f'{nominatim_url.rstrip("/")}/search',
params={'q': addr, 'format': 'json', 'limit': 1, 'countrycodes': 'ca'},
timeout=5,
headers={'User-Agent': 'fusion_tasks/1.0'},
headers=headers,
)
data = resp.json()
if isinstance(data, list) and data:

View File

@@ -2773,14 +2773,33 @@ class FusionTechnicianTask(models.Model):
_logger.warning(f"Travel time calculation failed for task {self.name}: {e}")
return False
@api.model
def _maps_api_headers(self):
"""Build request headers for the FusionMaps gateway.
When fusion_tasks.maps_api_key is set (public gateway at
maps.nexasystems.ca) we send it as X-API-Key. When unset (direct
LAN access to OSRM/Nominatim), we send only the User-Agent.
"""
headers = {'User-Agent': 'fusion_tasks/1.0'}
key = (self.env['ir.config_parameter'].sudo()
.get_param('fusion_tasks.maps_api_key', '') or '').strip()
if key:
headers['X-API-Key'] = key
return headers
@api.model
def _osrm_travel(self, osrm_url, from_lat, from_lng, to_lat, to_lng):
"""Query self-hosted OSRM /route for driving time + distance.
Returns (minutes, km) or (0, 0) on failure."""
"""Query OSRM /route for driving time + distance.
Returns (minutes, km) or (0, 0) on failure.
`osrm_url` may be either a direct OSRM endpoint (LAN) or a FusionMaps
gateway endpoint (public). The gateway requires X-API-Key.
"""
try:
url = (f'{osrm_url.rstrip("/")}/route/v1/driving/'
f'{from_lng},{from_lat};{to_lng},{to_lat}?overview=false')
resp = requests.get(url, timeout=5)
resp = requests.get(url, timeout=5, headers=self._maps_api_headers())
data = resp.json()
if data.get('code') == 'Ok' and data.get('routes'):
route = data['routes'][0]
@@ -2793,8 +2812,13 @@ class FusionTechnicianTask(models.Model):
@api.model
def _nominatim_geocode(self, nominatim_url, address):
"""Query self-hosted Nominatim /search for address → (lat, lng).
Returns (0.0, 0.0) on failure so callers can fall through to Google."""
"""Query Nominatim /search for address → (lat, lng). Returns
(0.0, 0.0) on failure so callers can fall through to Google.
`nominatim_url` may be either a direct Nominatim endpoint (LAN) or
a FusionMaps gateway endpoint (public) — the X-API-Key header is
added automatically when fusion_tasks.maps_api_key is set.
"""
if not address or not address.strip():
return 0.0, 0.0
try:
@@ -2806,8 +2830,7 @@ class FusionTechnicianTask(models.Model):
'countrycodes': 'ca',
}
resp = requests.get(
url, params=params, timeout=5,
headers={'User-Agent': 'fusion_tasks/1.0'},
url, params=params, timeout=5, headers=self._maps_api_headers(),
)
data = resp.json()
if isinstance(data, list) and data: