[REV] Revert "[IMP] base: select countries & state based on exact code, (useful for import and fast many2one)"
This reverts commit 09a22e3bef, 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.
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user