From 025e65a9259d2afea184bd0ecdc2672689cb9d6f Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 14 May 2018 12:02:34 +0200 Subject: [PATCH] [REV] Revert "[IMP] base: select countries & state based on exact code, (useful for import and fast many2one)" This reverts commit 09a22e3bef663143c10a6e502f1f207cdf69aab2, which was attempting to fix a use case that was actually working. It also created a duplicate `name_search()` method for res.country, in addition to the one aliased to `location_name_search()` It is indeed supported to import countries and states, using the country code or state code as the imported value. These will be matched uniquely thanks to the special `name_search()` performed for import, forcing the `operator`. And this is done while still allowing proper auto-completing for normal UI case, where the "exact code match" will only promote an extra result at the top of the suggested matches, rather than limit the results to a single match. The confusion apparently stemmed from the test case using "UK" as the country code. UK is not a valid ISO country code, so it would never match as expected. --- odoo/addons/base/models/res_country.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/odoo/addons/base/models/res_country.py b/odoo/addons/base/models/res_country.py index e6840b17517..a3984155b4e 100644 --- a/odoo/addons/base/models/res_country.py +++ b/odoo/addons/base/models/res_country.py @@ -92,16 +92,6 @@ class Country(models.Model): self.ensure_one() return re.findall(r'\((.+?)\)', self.address_format) - @api.model - def name_search(self, name='', args=None, operator='ilike', limit=100): - if args is None: - args = [] - records = self.search([('code', '=', name)] + args, limit=limit) - if not records: - search_domain = [('name', operator, name)] - records = self.search(search_domain + args, limit=limit) - return [(record.id, record.display_name) for record in records] - class CountryGroup(models.Model): _description = "Country Group" @@ -132,10 +122,10 @@ class CountryState(models.Model): args = [] if self.env.context.get('country_id'): args = args + [('country_id', '=', self.env.context.get('country_id'))] - records = self.search([('code', '=', name)] + args, limit=limit) - if not records: - search_domain = [('name', operator, name)] - records = self.search(search_domain + args, limit=limit) + firsts_records = self.search([('code', '=ilike', name)] + args, limit=limit) + search_domain = [('name', operator, name)] + search_domain.append(('id', 'not in', firsts_records.ids)) + records = firsts_records + self.search(search_domain + args, limit=limit) return [(record.id, record.display_name) for record in records]