From dc3ad1381f747871da9daa74b550fc15c9cfc3c3 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 18 Feb 2022 11:17:53 +0000 Subject: [PATCH] [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 --- addons/base_geolocalize/models/res_partner.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/base_geolocalize/models/res_partner.py b/addons/base_geolocalize/models/res_partner.py index da82ce2cfe4..844e42bbe18 100644 --- a/addons/base_geolocalize/models/res_partner.py +++ b/addons/base_geolocalize/models/res_partner.py @@ -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=''):