# -*- coding: utf-8 -*-
# © 2009 Jordi Esteve <jesteve@zikzakmedia.com>
# © 2012-2014 Ignacio Ibeas <ignacio@acysos.com>
# © 2016 Pedro M. Baeza
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from openerp import api, fields, models
from openerp.models import expression


class ResPartner(models.Model):
    _inherit = 'res.partner'

    comercial = fields.Char('Trade name', size=128, index=True)

    @api.model
    def search(self, args, offset=0, limit=None, order=None, count=False):
        """Include commercial name in direct name search. It serves also
        implicitly for name_search()"""
        if args and args[0][0] == 'name':
            args = expression.normalize_domain(args)
            exp = args[0]
            args = ['|',  ('comercial', exp[1], exp[2])] + args
        return super(ResPartner, self).search(
            args, offset=offset, limit=limit, order=order, count=count,
        )

    @api.multi
    def name_get(self):
        result = []
        name_pattern = self.env['ir.config_parameter'].get_param(
            'l10n_es_partner.name_pattern', default='')
        orig_name = dict(super(ResPartner, self).name_get())
        for partner in self:
            name = orig_name[partner.id]
            comercial = partner.comercial
            if comercial and name_pattern:
                name = name_pattern % {'name': name,
                                       'comercial_name': comercial}
            result.append((partner.id, name))
        return result

    @api.model
    def _commercial_fields(self):
        res = super(ResPartner, self)._commercial_fields()
        res += ['comercial']
        return res

@@ -680,93 +680,228 @@
     
-if args and args%5B0%5D%5B0%5D == 'name':%0A            args = expression.normalize_domain
+args = expression.normalize_domain(args)%0A        for arg in args:%0A            if isinstance(arg, (list, tuple)):%0A                if arg%5B0%5D == 'name' or arg%5B0%5D == 'display_name':%0A                    index = args.index
 (arg
-s
 )%0A  
@@ -914,47 +914,69 @@
     
-exp = args%5B0%5D%0A            args =
+        args = (%0A                        args%5B:index%5D +
  %5B'%7C',
- 
  ('c
@@ -990,31 +990,111 @@
 l', 
-exp
+arg
 %5B1%5D, 
-exp
+arg
 %5B2%5D)%5D +
- args
+%0A                        args%5Bindex:%5D%0A                    )%0A                    break
 %0A   

Improve search over other terms