Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Search for a name "starting with"...

By
Antoine Morit
on 6/18/14, 3:54 AM 1,819 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

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.

Leonardo Donelli
on 6/18/14, 5:01 AM

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

Antonio M. Vigliotti
on 6/18/14, 5:56 AM

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

Antonio M. Vigliotti
on 6/18/14, 5:57 AM
3

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 6/18/14, 4:55 AM

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.

1
Ivan Yelizariev
On 6/19/14, 2:49 AM

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

1

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 6/18/14, 5:49 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

5 follower(s)

Stats

Asked: 6/18/14, 3:54 AM
Seen: 1819 times
Last updated: 8/28/16, 8:51 PM