Search: part of string found, not whole string

Hello,
I have a product with number “PU5018”. It is found when I search for

  • PU
  • 50
  • PU5018
    It is not found by search for “5018”. Confusing to me every time.

The same happens when adding products to a sale. Is that intended behaviour?

Cheers,
Wolf

Yes, it is expected that when searching on codes tryton only search by the starting caracthers.
This is for products, but also for party code and other codes in the system.

Thank you for clarification.
This behaviour makes me a little angry every day. My product numbers are combined as of prefix-dimension. As far as I could observe, such a prefix-number combination is very common. When I now just look for the number, I would not find it. Think as of “ISO12345”, “DIN55”, “res220” (for "resistor 220ohms), “screw5x20” or whatever.

AFAIK, there are common algorithms to find any occurance of a sequence within a string, and I’d highly appreciate the usage of that.

RFE is 11682.

Those who wants to search by code should make query explicitly on the code.

I have no idea how to “make query explicitly on the code”.
And I guess, quite some other dummy users do neither.

Read twice :smile: Open your search popup and enter the your partial number in the code field. In that way you are telling Tryton to search explicitly (or specifically) on the code field and leave the rest of the fields out. When you don’t use the search popup but just type in something, Tryton will search multiple fields with a ‘general’ query.

Actually, in this rare case of exception, I did.
But I still do not agree. Search for part of a product number is such a common thing, that IMHO it should be covered without the search dialogue.

But more important: It should work in a sales or purchase process, where I do not have that type of dialogue.

Indeed no need to open the popup. Just type Code: in the searchfield before you type the part of the number. I personally would like the equal sign (=) instead of (:) because it’s more natural. You want to search for the code well type Code = <number>. But this is what it is.

You can also create a search bookmark to save it, but yeah it needs an extra mouse click.

What do you mean by that? Adding a product to a purchase or sale line? Most people search based on the (record)name of the product.

But I think you have to live with it or create your own module to revert this. See Party's rec_name should not search on bank accounts (#7347) · Issues · Tryton / Tryton · GitLab for the reason why it is how it is.

We did this to solve this problem:

class Product(metaclass=PoolMeta):
    __name__ = "product.product"

    @classmethod
    def search_rec_name(cls, name, clause):
        domain = super().search_rec_name(name, clause)
        return ['OR', domain,
            ('code',) + tuple(clause[1:]),
            ]

Should be AND for negative operators.

We did something cleaner for a customer:

    def search_rec_name(cls, name, clause):                                    
        domain = []                                                            
        for value in super().search_rec_name(name, clause):                    
            # Remove strip_wilcard from code                                   
            if value[0] == 'code':                                             
                value = (value[0],) + tuple(clause[1:])                        
            domain.append(value)                                                       
        return domain       

So we just remove the strip_wilcard and keep searching with the current value

I think we should left strip wildcard for code search only if it is a “full text” search.
So this way users could surround with double % the query and it will not be stripped for the code clause.
But this will work only if we strip only the first occurrence of %.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.