changes
This commit is contained in:
@@ -28,14 +28,29 @@ class ResPartner(models.Model):
|
||||
def _geocode_start_address(self, address):
|
||||
if not address or not address.strip():
|
||||
return 0.0, 0.0
|
||||
api_key = self.env['ir.config_parameter'].sudo().get_param(
|
||||
'fusion_claims.google_maps_api_key', '')
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
addr = address.strip()
|
||||
nominatim_url = (ICP.get_param('fusion_tasks.nominatim_url', '') or '').strip()
|
||||
if nominatim_url:
|
||||
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'},
|
||||
)
|
||||
data = resp.json()
|
||||
if isinstance(data, list) and data:
|
||||
return float(data[0]['lat']), float(data[0]['lon'])
|
||||
except Exception as e:
|
||||
_logger.warning("Nominatim start-address geocoding failed for '%s': %s", addr, e)
|
||||
api_key = ICP.get_param('fusion_claims.google_maps_api_key', '')
|
||||
if not api_key:
|
||||
return 0.0, 0.0
|
||||
try:
|
||||
resp = requests.get(
|
||||
'https://maps.googleapis.com/maps/api/geocode/json',
|
||||
params={'address': address.strip(), 'key': api_key, 'region': 'ca'},
|
||||
params={'address': addr, 'key': api_key, 'region': 'ca'},
|
||||
timeout=10,
|
||||
)
|
||||
data = resp.json()
|
||||
|
||||
Reference in New Issue
Block a user