From b70fe586f2971e8eedbf50ad710ded605e6ceafd Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Fri, 30 Dec 2016 01:34:16 -0800 Subject: [PATCH] [IMP] base: code aestetic, res_country & state [FIX] base: country & state, enforce the max number of records to the requested limit --- odoo/addons/base/res/res_country.py | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/odoo/addons/base/res/res_country.py b/odoo/addons/base/res/res_country.py index ed56ae0adc7..b5ade9b2c58 100644 --- a/odoo/addons/base/res/res_country.py +++ b/odoo/addons/base/res/res_country.py @@ -9,23 +9,6 @@ from odoo.tools.translate import _ _logger = logging.getLogger(__name__) -@api.model -def location_name_search(self, name='', args=None, operator='ilike', limit=100): - if args is None: - args = [] - - records = self.browse() - if len(name) == 2: - records = self.search([('code', 'ilike', name)] + args, limit=limit) - - search_domain = [('name', operator, name)] - if records: - search_domain.append(('id', 'not in', records.ids)) - records += self.search(search_domain + args, limit=limit) - - # the field 'display_name' calls name_get() to get its value - return [(record.id, record.display_name) for record in records] - class Country(models.Model): _name = 'res.country' @@ -67,7 +50,23 @@ class Country(models.Model): 'The code of the country must be unique !') ] - name_search = location_name_search + @api.model + def name_search(self, name='', args=None, operator='ilike', limit=100): + if args is None: + args = [] + + records = self.browse() + if len(name) == 2: + records = self.search([('code', '=ilike', name)] + args, limit=limit) + + search_domain = [('name', operator, name)] + if records: + search_domain.append(('id', 'not in', records.ids)) + records += self.search(search_domain + args, limit=limit-len(records)) + + # the field 'display_name' calls name_get() to get its value + return [(record.id, record.display_name) for record in records] + @api.model def create(self, vals): @@ -115,11 +114,12 @@ class CountryState(models.Model): if args is None: args = [] if self.env.context.get('country_id'): - args = args + [('country_id', '=', self.env.context.get('country_id'))] + args = args + [('country_id', '=', self.env.context['country_id'])] 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) + if len(firsts_records): + search_domain.append(('id', 'not in', firsts_records.ids)) + records = firsts_records + self.search(search_domain + args, limit=limit-len(firsts_records)) return [(record.id, record.display_name) for record in records]