Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
8 Відповіді
15559 Переглядів

Hello,

Is it possible to implement a very flexible (almost like fulltext) search for, i.e., Products in Lines.

The intention of this is for the user to as quickly as possible find the product (during new lines and not using the search view), which they might not even know the exact name, not even order of it, they just know part of the keywords.

For example, given the product name like, "Panel / White Color / 50x40".

I am looking for the way to enhance the product fields (in Order Line), so user can just type "50x40 white" to match the item. It is almost like google search to me.

Many thanks, Kitti U.

Аватар
Відмінити
Найкраща відповідь

I think that you are looking for the name_search function. This function is used for the search in many2one fields. This is for example the Product in the Order Line. You can override this function to fulfill you requirements.

As an example look at the name_search function of the Product (product.product).

def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
    if not args:
        args = []
    if name:
        ids = self.search(cr, user, [('default_code','=',name)]+ args, limit=limit, context=context)
        if not ids:
            ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit, context=context)
        if not ids:
            # Do not merge the 2 next lines into one single search, SQL search performance would be abysmal
            # on a database with thousands of matching products, due to the huge merge+unique needed for the
            # OR operator (and given the fact that the 'name' lookup results come from the ir.translation table
            # Performing a quick memory merge of ids in Python will give much better performance
            ids = set()
            ids.update(self.search(cr, user, args + [('default_code',operator,name)], limit=limit, context=context))
            if not limit or len(ids) < limit:
                # we may underrun the limit because of dupes in the results, that's fine
                ids.update(self.search(cr, user, args + [('name',operator,name)], limit=(limit and (limit-len(ids)) or False) , context=context))
            ids = list(ids)
        if not ids:
            ptrn = re.compile('(\[(.*?)\])')
            res = ptrn.search(name)
            if res:
                ids = self.search(cr, user, [('default_code','=', res.group(2))] + args, limit=limit, context=context)
    else:
        ids = self.search(cr, user, args, limit=limit, context=context)
    result = self.name_get(cr, user, ids, context=context)
    return result
Аватар
Відмінити
Автор

Hello Andreas. Yes I think this is what I am looking for. Thank you so much!

Where do i put this in odoo online version 16 ?

+1 for Odoo Online. Is there a way to put this code in Odoo Online ?

Найкраща відповідь

By default, in the search view, if you do 2 searches on the same field (e.g. "Panel" & "White"), OpenERP will apply a OR condition between both. This would result into: Product contain Panel OR product contain "White". So, this will not work for your example.

To do a AND between two criteria of the same field, you can use the advanced search.

For your example, if you are in the Sales Orders or Quotations, you can do this through applying two advanced searches:

Order Lines contains Panel
Order Lines contains White

Do not add conditions within the same advanced search, you must apply two searches.

Note that it will match Panel and White, regardless of the order.

Аватар
Відмінити
Найкраща відповідь

In search field name from product list (tree) or in field product_id from order line (form) you can use regular sql LIKE expression with wildcard: 'Panel%White%50x40'. You will receive all product with 'Panel' or 'White' or '50x40' in name.

Аватар
Відмінити

What if I need it to search in other fields than the name ?

This is BRILLIANT. Thank you.

Автор Найкраща відповідь

Thanks Fabian for the quick answer. But i think it is not exactly what I am looking for.

The intention of the question is for the user to as quickly as possible find the product (during new lines and not using the search view), which they might not even know the exact name, not even order of it, they just know part of the keywords.

Says, there are huge amount of products. And what they want to find is the one named, "Panel - White Color - 40x40".

I am looking for the way to enhance the product fields (in Order Line), so user can just type "40x40 white" to match the item. It is almost like google search to me.

Sorry if my question is not clear. But this is something many customer wanted (especially, organization with a lot of products)

Thank you, Kitti

Аватар
Відмінити

please edit your question for clarification instead of adding an answer

how did you solved this? I am also having same requirement in odoo14 and searching for a solution

Related Posts Відповіді Переглядів Дія
1
бер. 15
3464
0
бер. 15
7882
2
бер. 15
5132
0
груд. 23
4620
1
бер. 17
4054