[FIX] base, *: ensure name_search() returns lazy name_get() result

To avoid slowing down search like "{relational_field}" contains "{value}"
we always need to return the lazy name_get() for each [_]name_search method

closes odoo/odoo#36735

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Xavier ALT
2019-09-11 17:11:33 +00:00
parent 81e198aa5d
commit bea0a9edfe
18 changed files with 26 additions and 25 deletions
+4 -4
View File
@@ -361,7 +361,7 @@ class AccountAccount(models.Model):
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 self.browse(account_ids).name_get()
return models.lazy_name_get(self.browse(account_ids).with_user(name_get_uid))
@api.onchange('user_type_id')
def _onchange_user_type_id(self):
@@ -562,7 +562,7 @@ class AccountGroup(models.Model):
criteria_operator = ['|'] if operator not in expression.NEGATIVE_TERM_OPERATORS else ['&', '!']
domain = criteria_operator + [('code_prefix', '=ilike', name + '%'), ('name', operator, name)]
group_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
return self.browse(group_ids).name_get()
return models.lazy_name_get(self.browse(group_ids).with_user(name_get_uid))
class AccountRoot(models.Model):
@@ -1034,7 +1034,7 @@ class AccountJournal(models.Model):
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 self.browse(journal_ids).name_get()
return models.lazy_name_get(self.browse(journal_ids).with_user(name_get_uid))
@api.depends('inbound_payment_method_ids', 'outbound_payment_method_ids')
def _methods_compute(self):
@@ -1248,7 +1248,7 @@ class AccountTax(models.Model):
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 self.browse(tax_ids).name_get()
return models.lazy_name_get(self.browse(tax_ids).with_user(name_get_uid))
@api.model
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
+1 -1
View File
@@ -164,7 +164,7 @@ class AccountAnalyticAccount(models.Model):
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 self.browse(analytic_account_ids).name_get()
return models.lazy_name_get(self.browse(analytic_account_ids).with_user(name_get_uid))
class AccountAnalyticLine(models.Model):
+1 -1
View File
@@ -264,7 +264,7 @@ class FleetVehicle(models.Model):
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 self.browse(rec).name_get()
return models.lazy_name_get(self.browse(rec).with_user(name_get_uid))
def return_action_to_open(self):
""" This opens the xml view specified in xml_id for the current vehicle """
+1 -1
View File
@@ -118,7 +118,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 self.browse(equipment_ids).name_get()
return models.lazy_name_get(self.browse(equipment_ids).with_user(name_get_uid))
name = fields.Char('Equipment Name', required=True, translate=True)
company_id = fields.Many2one('res.company', string='Company',
+1 -1
View File
@@ -534,7 +534,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 self.browse(product_ids).name_get()
return models.lazy_name_get(self.browse(product_ids).with_user(name_get_uid))
@api.model
def view_header_get(self, view_id, view_type):
+1 -1
View File
@@ -361,7 +361,7 @@ class ProductTemplateAttributeLine(models.Model):
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 self.browse(attribute_ids).name_get()
return models.lazy_name_get(self.browse(attribute_ids).with_user(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):
+1 -1
View File
@@ -71,7 +71,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 self.browse(pricelist_ids).name_get()
return models.lazy_name_get(self.browse(pricelist_ids).with_user(name_get_uid))
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):
+1 -1
View File
@@ -134,7 +134,7 @@ class PurchaseOrder(models.Model):
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 self.browse(purchase_order_ids).name_get()
return models.lazy_name_get(self.browse(purchase_order_ids).with_user(name_get_uid))
@api.depends('date_order', 'currency_id', 'company_id', 'company_id.currency_id')
def _compute_currency_rate(self):
+1 -1
View File
@@ -130,7 +130,7 @@ class Location(models.Model):
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 self.browse(location_ids).name_get()
return models.lazy_name_get(self.browse(location_ids).with_user(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.'''
+1 -1
View File
@@ -160,7 +160,7 @@ class PickingType(models.Model):
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 self.browse(picking_ids).name_get()
return models.lazy_name_get(self.browse(picking_ids).with_user(name_get_uid))
@api.onchange('code')
def _onchange_picking_code(self):
+1 -1
View File
@@ -702,7 +702,7 @@ class IrActionsTodo(models.Model):
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 self.browse(action_ids).name_get()
return models.lazy_name_get(self.browse(action_ids).with_user(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):
+3 -2
View File
@@ -172,11 +172,12 @@ class IrModel(models.Model):
# overridden to allow searching both on model name (field 'model') and model
# description (field 'name')
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100):
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
if args is None:
args = []
domain = args + ['|', ('model', operator, name), ('name', operator, name)]
return super(IrModel, self).search(domain, limit=limit).name_get()
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))
def _drop_table(self):
for model in self:
+1 -1
View File
@@ -136,7 +136,7 @@ class ViewCustom(models.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 self.browse(view_ids).name_get()
return models.lazy_name_get(self.browse(view_ids).with_user(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):
+1 -1
View File
@@ -48,7 +48,7 @@ class Bank(models.Model):
if operator in expression.NEGATIVE_TERM_OPERATORS:
domain = ['&'] + domain
bank_ids = self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
return self.browse(bank_ids).name_get()
return models.lazy_name_get(self.browse(bank_ids).with_user(name_get_uid))
@api.onchange('country')
def _onchange_country_id(self):
+2 -2
View File
@@ -25,7 +25,7 @@ def location_name_search(self, name='', args=None, operator='ilike', limit=100):
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]
return models.lazy_name_get(records)
class Country(models.Model):
@@ -131,7 +131,7 @@ class CountryState(models.Model):
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 self.browse(state_ids).name_get()
return models.lazy_name_get(self.browse(state_ids).with_user(name_get_uid))
def name_get(self):
result = []
+1 -1
View File
@@ -116,7 +116,7 @@ class PartnerCategory(models.Model):
name = name.split(' / ')[-1]
args = [('name', operator, name)] + args
partner_category_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid)
return self.browse(partner_category_ids).name_get()
return models.lazy_name_get(self.browse(partner_category_ids).with_user(name_get_uid))
class PartnerTitle(models.Model):
+1 -1
View File
@@ -520,7 +520,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 self.browse(user_ids).name_get()
return models.lazy_name_get(self.browse(user_ids).with_user(name_get_uid))
def copy(self, default=None):
self.ensure_one()
+3 -3
View File
@@ -51,7 +51,7 @@ for name, field in MODELS:
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 self.browse(record_ids).name_get()
return models.lazy_name_get(self.browse(record_ids).with_user(name_get_uid))
else:
return []
@@ -72,7 +72,7 @@ class One2ManyChild(models.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 self.browse(record_ids).name_get()
return models.lazy_name_get(self.browse(record_ids).with_user(name_get_uid))
else:
return []
@@ -129,7 +129,7 @@ class Many2ManyChild(models.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 self.browse(record_ids).name_get()
return models.lazy_name_get(self.browse(record_ids).with_user(name_get_uid))
else:
return []