Browse Source

[ADD] allow to bypass standard name search entirely

pull/800/head
Holger Brunn 8 years ago
parent
commit
08db58d7c5
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 15
      base_name_search_improved/models/ir_model.py
  2. 1
      base_name_search_improved/views/ir_model.xml

15
base_name_search_improved/models/ir_model.py

@ -36,6 +36,10 @@ class ModelExtended(models.Model):
name_search_ids = fields.Many2many( name_search_ids = fields.Many2many(
'ir.model.fields', 'ir.model.fields',
string='Name Search Fields') string='Name Search Fields')
name_search_use_standard = fields.Boolean(
'Use standard search', default=True,
help='First try to find matches with the standard search',
)
def _register_hook(self, cr, ids=None): def _register_hook(self, cr, ids=None):
@ -44,9 +48,16 @@ class ModelExtended(models.Model):
@api.model @api.model
def name_search(self, name='', args=None, def name_search(self, name='', args=None,
operator='ilike', limit=100): operator='ilike', limit=100):
res = []
model_record = self.env['ir.model'].search([
('model', '=', str(self._model)),
])
# Perform standard name search # Perform standard name search
res = name_search.origin(
self, name=name, args=args, operator=operator, limit=limit)
if not name or model_record.name_search_use_standard:
res = name_search.origin(
self, name=name, args=args, operator=operator,
limit=limit,
)
enabled = self.env.context.get('name_search_extended', True) enabled = self.env.context.get('name_search_extended', True)
# Perform extended name search # Perform extended name search
# Note: Empty name causes error on # Note: Empty name causes error on

1
base_name_search_improved/views/ir_model.xml

@ -16,6 +16,7 @@
widget="many2many_tags" widget="many2many_tags"
domain="[('model_id', '=', id)]" domain="[('model_id', '=', id)]"
/> />
<field name="name_search_use_standard" />
</field> </field>
</field> </field>

Loading…
Cancel
Save