[FIX] base_geolocalize: Partial revert of #84266
Purpose ======= This @depends could be 'dangerous' because it would trigger a lot of calls to the GeoIP API. It would be more reasonable to make it lazy instead. So we just reset the geolocation to 0 when the address is modified without providing the new values, and the user can manually trigger the geolocation again when needed. For FSM, it will be updated when needed as the computation is triggered when the geolocation information is empty. Part-of: odoo/odoo#84890
This commit is contained in:
@@ -9,17 +9,17 @@ class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
date_localization = fields.Date(string='Geolocation Date')
|
||||
partner_latitude = fields.Float(compute="_compute_geo_coordinates", readonly=False, store=True)
|
||||
partner_longitude = fields.Float(compute="_compute_geo_coordinates", readonly=False, store=True)
|
||||
|
||||
@api.depends('street', 'zip', 'city', 'state_id', 'country_id')
|
||||
def _compute_geo_coordinates(self):
|
||||
for partner in self:
|
||||
if not (partner.city and partner.country_id):
|
||||
partner.partner_latitude = 0.0
|
||||
partner.partner_longitude = 0.0
|
||||
else:
|
||||
partner.geo_localize()
|
||||
def write(self, vals):
|
||||
# Reset latitude/longitude in case we modify the address without
|
||||
# updating the related geolocation fields
|
||||
if any(field in vals for field in ['street', 'zip', 'city', 'state_id', 'country_id']) \
|
||||
and not all('partner_%s' % field in vals for field in ['latitude', 'longitude']):
|
||||
vals.update({
|
||||
'partner_latitude': 0.0,
|
||||
'partner_longitude': 0.0,
|
||||
})
|
||||
return super().write(vals)
|
||||
|
||||
@api.model
|
||||
def _geo_localize(self, street='', zip='', city='', state='', country=''):
|
||||
|
||||
Reference in New Issue
Block a user