[FIX] base_geolocalize: Disable geolocalize on update/test mode

Purpose
=======

Avoid making useless external requests.

X-original-commit: 6742e410e4c28a1cd24d1f7ea679a563db693f00
This commit is contained in:
Yannick Tivisse
2022-02-18 10:19:08 +01:00
parent fcb5a0ed66
commit 99f7e35fc3
2 changed files with 10 additions and 1 deletions
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.tools import config
class ResPartner(models.Model):
@@ -29,6 +33,10 @@ class ResPartner(models.Model):
def geo_localize(self):
# We need country names in English below
if not self._context.get('force_geo_localize') \
and (self._context.get('import_file') \
or any(config[key] for key in ['test_enable', 'test_file', 'init', 'update'])):
return False
partners_not_geo_localized = self.env['res.partner']
for partner in self.with_context(lang='en_US'):
result = self._geo_localize(partner.street,
@@ -61,7 +61,8 @@ class TestPartnerAssign(TransactionCase):
# In order to test find nearest Partner functionality and assign to opportunity,
# I Set Geo Lattitude and Longitude according to partner address.
partner_be.geo_localize()
# YTI Note: We should probably mock the call
partner_be.with_context(force_geo_localize=True).geo_localize()
# I check Geo Latitude and Longitude of partner after set
self.assertTrue(50 < partner_be.partner_latitude < 51, "Latitude is wrong: 50 < %s < 51" % partner_be.partner_latitude)