Browse Source

Merge pull request #800 from hbrunn/8.0-base_name_search_improved-use_standard

[ADD] allow to bypass standard name search entirely
pull/461/merge
Daniel Reis 8 years ago
committed by GitHub
parent
commit
2e832d4cf9
  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