summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-06-17 12:18:27 +0000
committerRaphael Collet <rco@odoo.com>2020-08-18 13:02:41 +0000
commit1f48130d2bd055835ee428a21922331d126285a3 (patch)
tree594a6dd2999a290712839dfe92df47d0f7ed42b1
parent89963e0eddbf36d687799acb6ed1e8486cc178e7 (diff)
[REF] core: _name_search() now returns a list of ids
This provides a better API to search for records by name without the formatting part (`display_name`). This also simplifies all the overridings of `_name_search` that no longer need to call `name_get()`. The call to `name_get()` is done in method `name_search` in a generic way.
-rw-r--r--addons/account/models/account_account.py6
-rw-r--r--addons/account/models/account_journal.py3
-rw-r--r--addons/account/models/account_tax.py3
-rw-r--r--addons/analytic/models/analytic_account.py3
-rw-r--r--addons/fleet/models/fleet_vehicle.py3
-rw-r--r--addons/l10n_latam_invoice_document/models/l10n_latam_document_type.py3
-rw-r--r--addons/maintenance/models/maintenance.py2
-rw-r--r--addons/product/models/product.py12
-rw-r--r--addons/product/models/product_attribute.py3
-rw-r--r--addons/product/models/product_pricelist.py2
-rw-r--r--addons/product/models/product_template.py13
-rw-r--r--addons/purchase/models/purchase.py3
-rw-r--r--addons/purchase_stock/tests/test_product_template.py6
-rw-r--r--addons/sale/models/sale.py3
-rw-r--r--addons/stock/models/stock_location.py3
-rw-r--r--addons/stock/models/stock_picking.py3
-rw-r--r--odoo/addons/base/models/ir_actions.py3
-rw-r--r--odoo/addons/base/models/ir_model.py3
-rw-r--r--odoo/addons/base/models/ir_ui_view.py3
-rw-r--r--odoo/addons/base/models/res_bank.py3
-rw-r--r--odoo/addons/base/models/res_country.py41
-rw-r--r--odoo/addons/base/models/res_partner.py9
-rw-r--r--odoo/addons/base/models/res_users.py2
-rw-r--r--odoo/addons/test_impex/models.py9
-rw-r--r--odoo/models.py14
25 files changed, 67 insertions, 91 deletions
diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py
index 6dc128dc316..d9b5fa936b1 100644
--- a/addons/account/models/account_account.py
+++ b/addons/account/models/account_account.py
@@ -331,8 +331,7 @@ class AccountAccount(models.Model):
domain = ['|', ('code', '=ilike', name.split(' ')[0] + '%'), ('name', operator, name)]
if operator in expression.NEGATIVE_TERM_OPERATORS:
domain = ['&', '!'] + domain[1:]
- account_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(account_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
@api.onchange('user_type_id')
def _onchange_user_type_id(self):
@@ -524,8 +523,7 @@ class AccountGroup(models.Model):
else:
criteria_operator = ['|'] if operator not in expression.NEGATIVE_TERM_OPERATORS else ['&', '!']
domain = criteria_operator + [('code_prefix_start', '=ilike', name + '%'), ('name', operator, name)]
- group_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(group_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
@api.constrains('code_prefix_start', 'code_prefix_end')
def _constraint_prefix_overlap(self):
diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py
index 9be7d9c68b5..f9e5ef905fa 100644
--- a/addons/account/models/account_journal.py
+++ b/addons/account/models/account_journal.py
@@ -540,8 +540,7 @@ class AccountJournal(models.Model):
else:
connector = '&' if operator in expression.NEGATIVE_TERM_OPERATORS else '|'
domain = [connector, ('code', operator, name), ('name', operator, name)]
- journal_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(journal_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
@api.depends('inbound_payment_method_ids', 'outbound_payment_method_ids')
def _methods_compute(self):
diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py
index 6d04db8b3c6..56b65e5d8ad 100644
--- a/addons/account/models/account_tax.py
+++ b/addons/account/models/account_tax.py
@@ -212,8 +212,7 @@ class AccountTax(models.Model):
else:
connector = '&' if operator in expression.NEGATIVE_TERM_OPERATORS else '|'
domain = [connector, ('description', operator, name), ('name', operator, name)]
- tax_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(tax_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
@api.model
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py
index 5c99a9dfcdf..9bbfe4a254c 100644
--- a/addons/analytic/models/analytic_account.py
+++ b/addons/analytic/models/analytic_account.py
@@ -165,8 +165,7 @@ class AccountAnalyticAccount(models.Model):
# we have to cut the search in two searches ... https://github.com/odoo/odoo/issues/25175
partner_ids = self.env['res.partner']._search([('name', operator, name)], limit=limit, access_rights_uid=name_get_uid)
domain = ['|', '|', ('code', operator, name), ('name', operator, name), ('partner_id', 'in', partner_ids)]
- analytic_account_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(analytic_account_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
class AccountAnalyticLine(models.Model):
diff --git a/addons/fleet/models/fleet_vehicle.py b/addons/fleet/models/fleet_vehicle.py
index 87519bdafd0..a74add5e386 100644
--- a/addons/fleet/models/fleet_vehicle.py
+++ b/addons/fleet/models/fleet_vehicle.py
@@ -273,8 +273,7 @@ class FleetVehicle(models.Model):
domain = []
else:
domain = ['|', ('name', operator, name), ('driver_id.name', operator, name)]
- rec = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(rec).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
def return_action_to_open(self):
""" This opens the xml view specified in xml_id for the current vehicle """
diff --git a/addons/l10n_latam_invoice_document/models/l10n_latam_document_type.py b/addons/l10n_latam_invoice_document/models/l10n_latam_document_type.py
index 40b9f55ee98..3eb6bd04e0b 100644
--- a/addons/l10n_latam_invoice_document/models/l10n_latam_document_type.py
+++ b/addons/l10n_latam_invoice_document/models/l10n_latam_document_type.py
@@ -50,8 +50,7 @@ class L10nLatamDocumentType(models.Model):
domain = []
else:
domain = ['|', ('name', 'ilike', name), ('code', 'ilike', name)]
- ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return self.browse(ids).name_get()
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
def _filter_taxes_included(self, taxes):
""" This method is to be inherited by different localizations and must return filter the given taxes recordset
diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py
index 8224cc52d93..fcb87179010 100644
--- a/addons/maintenance/models/maintenance.py
+++ b/addons/maintenance/models/maintenance.py
@@ -107,7 +107,7 @@ class MaintenanceEquipment(models.Model):
equipment_ids = self._search([('name', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid)
if not equipment_ids:
equipment_ids = self._search([('name', operator, name)] + args, limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(equipment_ids).with_user(name_get_uid))
+ return equipment_ids
name = fields.Char('Equipment Name', required=True, translate=True)
company_id = fields.Many2one('res.company', string='Company',
diff --git a/addons/product/models/product.py b/addons/product/models/product.py
index 2349ac40194..7e192b84ee8 100644
--- a/addons/product/models/product.py
+++ b/addons/product/models/product.py
@@ -507,15 +507,15 @@ class ProductProduct(models.Model):
positive_operators = ['=', 'ilike', '=ilike', 'like', '=like']
product_ids = []
if operator in positive_operators:
- product_ids = self._search([('default_code', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid)
+ product_ids = list(self._search([('default_code', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid))
if not product_ids:
- product_ids = self._search([('barcode', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid)
+ product_ids = list(self._search([('barcode', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid))
if not product_ids and operator not in expression.NEGATIVE_TERM_OPERATORS:
# Do not merge the 2 next lines into one single search, SQL search performance would be abysmal
# on a database with thousands of matching products, due to the huge merge+unique needed for the
# OR operator (and given the fact that the 'name' lookup results come from the ir.translation table
# Performing a quick memory merge of ids in Python will give much better performance
- product_ids = self._search(args + [('default_code', operator, name)], limit=limit)
+ product_ids = list(self._search(args + [('default_code', operator, name)], limit=limit))
if not limit or len(product_ids) < limit:
# we may underrun the limit because of dupes in the results, that's fine
limit2 = (limit - len(product_ids)) if limit else False
@@ -527,12 +527,12 @@ class ProductProduct(models.Model):
['&', ('default_code', '=', False), ('name', operator, name)],
])
domain = expression.AND([args, domain])
- product_ids = self._search(domain, limit=limit, access_rights_uid=name_get_uid)
+ product_ids = list(self._search(domain, limit=limit, access_rights_uid=name_get_uid))
if not product_ids and operator in positive_operators:
ptrn = re.compile('(\[(.*?)\])')
res = ptrn.search(name)
if res:
- product_ids = self._search([('default_code', '=', res.group(2))] + args, limit=limit, access_rights_uid=name_get_uid)
+ product_ids = list(self._search([('default_code', '=', res.group(2))] + args, limit=limit, access_rights_uid=name_get_uid))
# still no results, partner in context: search on supplier info as last hope to find something
if not product_ids and self._context.get('partner_id'):
suppliers_ids = self.env['product.supplierinfo']._search([
@@ -544,7 +544,7 @@ class ProductProduct(models.Model):
product_ids = self._search([('product_tmpl_id.seller_ids', 'in', suppliers_ids)], limit=limit, access_rights_uid=name_get_uid)
else:
product_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(product_ids).with_user(name_get_uid))
+ return product_ids
@api.model
def view_header_get(self, view_id, view_type):
diff --git a/addons/product/models/product_attribute.py b/addons/product/models/product_attribute.py
index 1f879fbca7b..8c252c22448 100644
--- a/addons/product/models/product_attribute.py
+++ b/addons/product/models/product_attribute.py
@@ -371,8 +371,7 @@ class ProductTemplateAttributeLine(models.Model):
if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
args = args or []
domain = ['|', ('attribute_id', operator, name), ('value_ids', operator, name)]
- attribute_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(attribute_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
return super(ProductTemplateAttributeLine, self)._name_search(name=name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _without_no_variant_attributes(self):
diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py
index d1ef0ec714c..42378e4e00c 100644
--- a/addons/product/models/product_pricelist.py
+++ b/addons/product/models/product_pricelist.py
@@ -73,7 +73,7 @@ class Pricelist(models.Model):
# regular search() to apply ACLs - may limit results below limit in some cases
pricelist_ids = self._search([('id', 'in', ids)], limit=limit, access_rights_uid=name_get_uid)
if pricelist_ids:
- return models.lazy_name_get(self.browse(pricelist_ids).with_user(name_get_uid))
+ return pricelist_ids
return super(Pricelist, self)._name_search(name, args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _compute_price_rule_multi(self, products_qty_partner, date=False, uom_id=False):
diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py
index 2039468696a..50685ef014a 100644
--- a/addons/product/models/product_template.py
+++ b/addons/product/models/product_template.py
@@ -468,8 +468,8 @@ class ProductTemplate(models.Model):
while True:
domain = templates and [('product_tmpl_id', 'not in', templates.ids)] or []
args = args if args is not None else []
- products_ns = Product._name_search(name, args+domain, operator=operator, name_get_uid=name_get_uid)
- products = Product.browse([x[0] for x in products_ns])
+ products_ids = Product._name_search(name, args+domain, operator=operator, name_get_uid=name_get_uid)
+ products = Product.browse(products_ids)
new_templates = products.mapped('product_tmpl_id')
if new_templates & templates:
"""Product._name_search can bypass the domain we passed (search on supplier info).
@@ -479,8 +479,8 @@ class ProductTemplate(models.Model):
current_round_templates = self.browse([])
if not products:
domain_template = args + domain_no_variant + (templates and [('id', 'not in', templates.ids)] or [])
- template_ns = super(ProductTemplate, self)._name_search(name=name, args=domain_template, operator=operator, limit=limit, name_get_uid=name_get_uid)
- current_round_templates |= self.browse([ns[0] for ns in template_ns])
+ template_ids = super(ProductTemplate, self)._name_search(name=name, args=domain_template, operator=operator, limit=limit, name_get_uid=name_get_uid)
+ current_round_templates |= self.browse(template_ids)
templates |= current_round_templates
if (not products and not current_round_templates) or (limit and (len(templates) > limit)):
break
@@ -491,13 +491,12 @@ class ProductTemplate(models.Model):
# FIXME awa: this is really not performant at all but after discussing with the team
# we don't see another way to do it
if not limit or len(searched_ids) < limit:
- searched_ids |= set([template_id[0] for template_id in
- super(ProductTemplate, self)._name_search(
+ searched_ids |= set(super(ProductTemplate, self)._name_search(
name,
args=args,
operator=operator,
limit=limit,
- name_get_uid=name_get_uid)])
+ name_get_uid=name_get_uid))
# re-apply product.template order + name_get
return super(ProductTemplate, self)._name_search(
diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py
index 09c2697cd2e..d4f23bbc860 100644
--- a/addons/purchase/models/purchase.py
+++ b/addons/purchase/models/purchase.py
@@ -163,8 +163,7 @@ class PurchaseOrder(models.Model):
domain = []
if name:
domain = ['|', ('name', operator, name), ('partner_ref', operator, name)]
- purchase_order_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(purchase_order_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
@api.depends('date_order', 'currency_id', 'company_id', 'company_id.currency_id')
def _compute_currency_rate(self):
diff --git a/addons/purchase_stock/tests/test_product_template.py b/addons/purchase_stock/tests/test_product_template.py
index 2cb82886c0d..0692ac02033 100644
--- a/addons/purchase_stock/tests/test_product_template.py
+++ b/addons/purchase_stock/tests/test_product_template.py
@@ -21,6 +21,6 @@ class TestProductTemplate(TransactionCase):
'seller_ids': [seller.id],
'purchase_ok': True,
})
- ns = self.env['product.template'].with_context(partner_id=partner.id)._name_search('VOB2', [['purchase_ok', '=', True]])
- self.assertEqual(len(ns), 1, "_name_search should have 1 item")
- self.assertEqual(ns[0][1]._value, '[VOB2A] Rubber Duck', "_name_search should return the expected result")
+ ns = self.env['product.template'].with_context(partner_id=partner.id).name_search('VOB2', [['purchase_ok', '=', True]])
+ self.assertEqual(len(ns), 1, "name_search should have 1 item")
+ self.assertEqual(ns[0][1], '[VOB2A] Rubber Duck', "name_search should return the expected result")
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index b9ad7c8b796..1bdc685b134 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -521,8 +521,7 @@ class SaleOrder(models.Model):
args or [],
['|', ('name', operator, name), ('partner_id.name', operator, name)]
])
- order_ids = self._search(domain, limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(order_ids).with_user(name_get_uid))
+ return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
return super(SaleOrder, self)._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _prepare_invoice(self):
diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py
index 2d82f3e84d5..cd2b7643aa2 100644
--- a/addons/stock/models/stock_location.py
+++ b/addons/stock/models/stock_location.py
@@ -130,8 +130,7 @@ class Location(models.Model):
domain = [('barcode', operator, name), ('complete_name', operator, name)]
else:
domain = ['|', ('barcode', operator, name), ('complete_name', operator, name)]
- location_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(location_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
def _get_putaway_strategy(self, product):
''' Returns the location where the product has to be put, if any compliant putaway strategy is found. Otherwise returns None.'''
diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py
index 95b77f2997c..9c266ce95c3 100644
--- a/addons/stock/models/stock_picking.py
+++ b/addons/stock/models/stock_picking.py
@@ -161,8 +161,7 @@ class PickingType(models.Model):
domain = []
if name:
domain = ['|', ('name', operator, name), ('warehouse_id.name', operator, name)]
- picking_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(picking_ids).with_user(name_get_uid))
+ return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
@api.onchange('code')
def _onchange_picking_code(self):
diff --git a/odoo/addons/base/models/ir_actions.py b/odoo/addons/base/models/ir_actions.py
index 51440593b2f..0934e7f38f4 100644
--- a/odoo/addons/base/models/ir_actions.py
+++ b/odoo/addons/base/models/ir_actions.py
@@ -760,8 +760,7 @@ class IrActionsTodo(models.Model):
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
args = args or []
if name:
- action_ids = self._search(expression.AND([[('action_id', operator, name)], args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(action_ids).with_user(name_get_uid))
+ return self._search(expression.AND([[('action_id', operator, name)], args]), limit=limit, access_rights_uid=name_get_uid)
return super(IrActionsTodo, self)._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def action_launch(self):
diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py
index 18f113d0cac..3577133891b 100644
--- a/odoo/addons/base/models/ir_model.py
+++ b/odoo/addons/base/models/ir_model.py
@@ -257,8 +257,7 @@ class IrModel(models.Model):
if args is None:
args = []
domain = args + ['|', ('model', operator, name), ('name', operator, name)]
- model_ids = self._search(domain, limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(model_ids).with_user(name_get_uid))
+ return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
def _drop_table(self):
for model in self:
diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py
index f6350ef0ed8..ca2d69699cc 100644
--- a/odoo/addons/base/models/ir_ui_view.py
+++ b/odoo/addons/base/models/ir_ui_view.py
@@ -136,8 +136,7 @@ class ViewCustom(models.Model):
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
if name:
- view_ids = self._search([('user_id', operator, name)] + (args or []), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(view_ids).with_user(name_get_uid))
+ return self._search([('user_id', operator, name)] + (args or []), limit=limit, access_rights_uid=name_get_uid)
return super(ViewCustom, self)._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _auto_init(self):
diff --git a/odoo/addons/base/models/res_bank.py b/odoo/addons/base/models/res_bank.py
index 268a6668e44..b4c8c46a8e0 100644
--- a/odoo/addons/base/models/res_bank.py
+++ b/odoo/addons/base/models/res_bank.py
@@ -48,8 +48,7 @@ class Bank(models.Model):
domain = ['|', ('bic', '=ilike', name + '%'), ('name', operator, name)]
if operator in expression.NEGATIVE_TERM_OPERATORS:
domain = ['&'] + domain
- bank_ids = self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(bank_ids).with_user(name_get_uid))
+ return self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
@api.onchange('country')
def _onchange_country_id(self):
diff --git a/odoo/addons/base/models/res_country.py b/odoo/addons/base/models/res_country.py
index 112791229fe..ad53687d981 100644
--- a/odoo/addons/base/models/res_country.py
+++ b/odoo/addons/base/models/res_country.py
@@ -10,24 +10,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 models.lazy_name_get(records)
-
-
class Country(models.Model):
_name = 'res.country'
_description = 'Country'
@@ -77,7 +59,20 @@ class Country(models.Model):
'The code of the country must be unique !')
]
- name_search = location_name_search
+ def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
+ if args is None:
+ args = []
+
+ ids = []
+ if len(name) == 2:
+ ids = list(self._search([('code', 'ilike', name)] + args, limit=limit))
+
+ search_domain = [('name', operator, name)]
+ if ids:
+ search_domain.append(('id', 'not in', ids))
+ ids += list(self._search(search_domain + args, limit=limit))
+
+ return ids
@api.model_create_multi
def create(self, vals_list):
@@ -133,8 +128,12 @@ class CountryState(models.Model):
domain = [('name', operator, name)]
first_state_ids = self._search(expression.AND([first_domain, args]), limit=limit, access_rights_uid=name_get_uid) if first_domain else []
- state_ids = first_state_ids + [state_id for state_id in self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) if not state_id in first_state_ids]
- return models.lazy_name_get(self.browse(state_ids).with_user(name_get_uid))
+ return list(first_state_ids) + [
+ state_id
+ for state_id in self._search(expression.AND([domain, args]),
+ limit=limit, access_rights_uid=name_get_uid)
+ if state_id not in first_state_ids
+ ]
def name_get(self):
result = []
diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py
index 39c743d96c3..b9187e30e58 100644
--- a/odoo/addons/base/models/res_partner.py
+++ b/odoo/addons/base/models/res_partner.py
@@ -117,8 +117,7 @@ class PartnerCategory(models.Model):
# Be sure name_search is symetric to name_get
name = name.split(' / ')[-1]
args = [('name', operator, name)] + args
- partner_category_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(partner_category_ids).with_user(name_get_uid))
+ return self._search(args, limit=limit, access_rights_uid=name_get_uid)
class PartnerTitle(models.Model):
@@ -797,12 +796,8 @@ class Partner(models.Model):
query += ' limit %s'
where_clause_params.append(limit)
self.env.cr.execute(query, where_clause_params)
- partner_ids = [row[0] for row in self.env.cr.fetchall()]
+ return [row[0] for row in self.env.cr.fetchall()]
- if partner_ids:
- return models.lazy_name_get(self.browse(partner_ids))
- else:
- return []
return super(Partner, self)._name_search(name, args, operator=operator, limit=limit, name_get_uid=name_get_uid)
@api.model
diff --git a/odoo/addons/base/models/res_users.py b/odoo/addons/base/models/res_users.py
index 33a84f53292..e642e4d5c30 100644
--- a/odoo/addons/base/models/res_users.py
+++ b/odoo/addons/base/models/res_users.py
@@ -622,7 +622,7 @@ class Users(models.Model):
user_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
if not user_ids:
user_ids = self._search(expression.AND([[('name', operator, name)], args]), limit=limit, access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(user_ids).with_user(name_get_uid))
+ return user_ids
def copy(self, default=None):
self.ensure_one()
diff --git a/odoo/addons/test_impex/models.py b/odoo/addons/test_impex/models.py
index 2b6391e62d3..685cec9b80e 100644
--- a/odoo/addons/test_impex/models.py
+++ b/odoo/addons/test_impex/models.py
@@ -50,8 +50,7 @@ for name, field in MODELS:
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if isinstance(name, str) and name.split(':')[0] == self._name:
- record_ids = self._search([('value', operator, int(name.split(':')[1]))], access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(record_ids).with_user(name_get_uid))
+ return self._search([('value', operator, int(name.split(':')[1]))], access_rights_uid=name_get_uid)
else:
return []
@@ -72,8 +71,7 @@ class One2ManyChild(models.Model):
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if isinstance(name, str) and name.split(':')[0] == self._name:
- record_ids = self._search([('value', operator, int(name.split(':')[1]))], access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(record_ids).with_user(name_get_uid))
+ return self._search([('value', operator, int(name.split(':')[1]))], access_rights_uid=name_get_uid)
else:
return []
@@ -130,8 +128,7 @@ class Many2ManyChild(models.Model):
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if isinstance(name, str) and name.split(':')[0] == self._name:
- record_ids = self._search([('value', operator, int(name.split(':')[1]))], access_rights_uid=name_get_uid)
- return models.lazy_name_get(self.browse(record_ids).with_user(name_get_uid))
+ return self._search([('value', operator, int(name.split(':')[1]))], access_rights_uid=name_get_uid)
else:
return []
diff --git a/odoo/models.py b/odoo/models.py
index a3b221433f7..99486832526 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -1753,21 +1753,23 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
:rtype: list
:return: list of pairs ``(id, text_repr)`` for all matching records.
"""
- return self._name_search(name, args, operator, limit=limit)
+ ids = self._name_search(name, args, operator, limit=limit)
+ return self.browse(ids).sudo().name_get()
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
- # private implementation of name_search, allows passing a dedicated user
- # for the name_get part to solve some access rights issues
+ """ _name_search(name='', args=None, operator='ilike', limit=100, name_get_uid=None) -> ids
+
+ Private implementation of name_search, allows passing a dedicated user
+ for the name_get part to solve some access rights issues.
+ """
args = list(args or [])
# optimize out the default criterion of ``ilike ''`` that matches everything
if not self._rec_name:
_logger.warning("Cannot execute name_search, no _rec_name defined on %s", self._name)
elif not (name == '' and operator == 'ilike'):
args += [(self._rec_name, operator, name)]
- ids = self._search(args, limit=limit, access_rights_uid=name_get_uid)
- recs = self.browse(ids)
- return lazy_name_get(recs.with_user(name_get_uid))
+ return self._search(args, limit=limit, access_rights_uid=name_get_uid)
@api.model
def _add_missing_default_values(self, values):