Skip to Content
Menu
This question has been flagged
3 Replies
17820 Views

When you use a search, for example in the partner view, you get all names containing the word searched.

example for a search "te" :

ABC Company Limited, Tested One, View Technologies,  etc...

Is there a way to get only the names starting with the word searched ?

For the same example, for a search "te", we will only get :

Tested One

Thanks for help

Avatar
Discard

Bogus answer. i accidentally clicked on "Convert to answer" on a comment (that wasn't even mine!) and I can't find a way to delete this answer.

In search box, click on little down arrow and open full search menu. Select advanced search, choice name beginnig with Antonio Maria Vigliotti

Sorry, Leonardo is right. There is no option "beginning with" in advanced search

Best Answer

Let's stick to your example: res.partner view

The search view has this field:

<field name="name" filter_domain="['|','|',('name','ilike',self),('parent_id','ilike',self),('ref','=',self)]"></field>

Let's focus on the first search tuple: ('name','ilike',self)

That filters all partners, that has the entered search name as part of the their name. (Note that ilike operator is case-insensitive (ilike is postgresql specific), while like is case-sensitive). SQL: name ILIKE '%self%'

What you want to perform is the query: name ILIKE 'self%'.

The like and ilike operators in OpenERP automatically add the wildcards arround the search term. To avoid that, you should use =like and =ilike operators. You then need to add the wildcard manually (otherwise it will search for the exact term), so I would guess you should change the search tuple to:

(name,'=ilike',self+'%')

I'm not sure you can add strings this way, but give it a try. Also change the other search tuples accordingly.

 

EDIT (since the reactions on this answer are wrongly brisk):

I've tested the mentioned search domain (name,'=ilike',self+'%') and it doesn't work.

What did work was (name,'=ilike',self) and searching for 'te%'. But that's not very userfriendly.

So the derived question from the OPs question is: How to automatically add the wildcard to the search term?

 

Best regards.

Avatar
Discard
Best Answer

I have tested René Schuster's solution on latest version openerp and it works:

<field name="name" filter_domain="['|','|',('name','=ilike',self+'%'),('parent_id','=ilike',self+'%'),('ref','=',self)]"></field>

it sends correct request ang get correct result

POST DATA:

{"jsonrpc":"2.0","method":"call","params":{"model":"res.partner","fields":["sale_order_count","title","parent_id","street","country_id","email","street2","state_id","display_name","zip","color","city","opportunity_count","function","phone","has_image","is_company","meeting_count","mobile","category_id","__last_update"],"domain":["|","|",["name","=ilike","a%"],["parent_id","=ilike","a%"],["ref","=","a"]],"context":{"lang":"ru_RU","tz":"Asia/Yekaterinburg","uid":1},"offset":0,"limit":40,"sort":""},"id":903990513}

It returns only contacts starting with "a".

So, the solution is to modify base.view_res_partner_filter view with filter_domain above

Avatar
Discard
Best Answer

Hi,

You can use '=like' or '=ilike' operator in domain for starting with comparision.

This is since v5, glad to share I worked for expression.py.

Thanks.

Avatar
Discard
Related Posts Replies Views Activity
3
May 24
794
2
Dec 19
2175
1
Mar 24
447
5
Mar 22
14141
2
May 20
3301