Backport of 84d5d27 from 18.0 (no adaptation needed: the stock
``base_geocoder._call_openstreetmap`` is identical between 16.0 and
18.0).
The stock ``base_geocoder._call_openstreetmap`` sends a generic Odoo
``User-Agent`` shared across thousands of instances, which Nominatim
rate-limits and blocks (HTTP 429 "Too many requests"), so mass
geolocation fails regardless of client-side throttling.
Override ``_call_openstreetmap`` to:
- send a deployment-specific ``User-Agent`` read from a new system
parameter ``partner_geolocalize_usability.user_agent`` (shipped with an
obvious placeholder so an unconfigured instance fails loudly instead of
silently reusing the banned generic agent);
- throttle requests to one per second (``time.sleep``) before each call,
complying with the Nominatim usage policy even when callers loop over
many partners;
- return ``None`` instead of raising ``IndexError`` when Nominatim
returns an empty result for an unknown address.
Document the required system parameter in the README and add tests
covering the User-Agent selection, throttling and empty/blank results.
Verified on odoo16 container (image rc_16.0-ELABORE-LIGHT, dev mount):
module install with the new data file, 5 tests 0 failed/0 error, and a
real geocoding call to Nominatim with a configured User-Agent returned
correct coordinates.
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
# Copyright 2023 Stéphan Sainléger (Elabore)
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
{
|
|
"name": "partner_geolocalize_usability",
|
|
"version": "16.0.1.0.0",
|
|
"author": "Elabore",
|
|
"website": "https://elabore.coop",
|
|
"maintainer": "Stéphan Sainléger",
|
|
"license": "AGPL-3",
|
|
"category": "Tools",
|
|
"summary": "Brings several enhancements on geolocalize functionnalities",
|
|
# any module necessary for this one to work correctly
|
|
"depends": [
|
|
"base",
|
|
"base_geolocalize"
|
|
],
|
|
"qweb": [],
|
|
"external_dependencies": {
|
|
"python": ["requests"],
|
|
},
|
|
# always loaded
|
|
"data": [
|
|
"data/ir_config_parameter.xml",
|
|
"views/res_partner.xml",
|
|
],
|
|
# only loaded in demonstration mode
|
|
"demo": [],
|
|
"js": [],
|
|
"css": [],
|
|
"installable": True,
|
|
# Install this module automatically if all dependency have been previously
|
|
# and independently installed. Used for synergetic or glue modules.
|
|
"auto_install": False,
|
|
"application": False,
|
|
} |