Reputation: 3
Hi guys i was using Odoo 10, Is there a way to search partner using vat number instead of partner name when creating invoice?
Thanks in advance
Upvotes: 0
Views: 1544
Reputation: 1938
Yes. There is a way to do that. You can try my solution
partner
field to set, that you want to search by vat. Here you can use xpath
. context="{'search_by_vat': True}"
name_search
in res.partner
:class Partner(models.Model):
_inherit = 'res.partner'
@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
if self._context.get('search_by_vat', False):
if name:
args = args If i Want to search in both name and vat what should i do?if args else []
args.append(['vat', 'ilike', name])
name = ''
return super(Partner, self).name_search(name=name, args=args, operator=operator, limit=limit)
If i Want to search in both name and vat what should i do?
You can use ['name', 'ilike', name] or ['vat', 'ilike', name]
class Partner(models.Model):
_inherit = 'res.partner'
@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
if self._context.get('search_by_vat', False):
if name:
args = args if args else []
args.extend(['|', ['name', 'ilike', name], ['vat', 'ilike', name]])
name = ''
return super(Partner, self).name_search(name=name, args=args, operator=operator, limit=limit)
Upvotes: 2