It is currently Mon May 21, 2012 7:35 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: what happened with name_search function?
PostPosted: Fri Aug 05, 2011 5:47 pm 
Offline

Joined: Tue Jan 18, 2011 5:16 pm
Posts: 236
Hi,

I have added this piece of code to name_search function in product.py
Code:
            if not len(ids):
                ids = self.search(cr, user, [('description','=',name)]+ args, limit=limit, context=context)


the original function is here :
Code:
   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 len(ids):
                ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit, context=context)
            if not len(ids):
                ids = self.search(cr, user, ['|',('name',operator,name),('default_code',operator,name)] + args, limit=limit, context=context)
            if not len(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

I needed that to search also in product description
and it was working.

After latest code update does not work anymore. I mean does not return any product even if is called.

Any idea?

Thanks

_________________
OpenERP debugging with Eclipse on headless server


Top
 Profile  
 
 Post subject: Re: what happened with name_search function?
PostPosted: Fri Aug 05, 2011 9:16 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
Go to launchpad and check the merges to see if anything changed, I doubt it though, definitely not in stable. More likely your search is wrong, or you installed a module that over rode the behaviour.

In any case, unless you want a specific code a better search term is

Code:
if not len(ids):
                ids = self.search(cr, user, [('description',operator,name)]+ args, limit=limit, context=context)

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: what happened with name_search function?
PostPosted: Mon Aug 08, 2011 11:07 am 
Offline

Joined: Tue Jan 18, 2011 5:16 pm
Posts: 236
Thanks, is working ok.
Can you take a look at the name_search function and tell me how to achieve the search in name , description, default_code in the same iteration?

The way I modified the function, if it finds the term in the name it stops, even if I have a lot of pozitive matches in the description.
Thanks Again.

_________________
OpenERP debugging with Eclipse on headless server


Top
 Profile  
 
 Post subject: Re: what happened with name_search function?
PostPosted: Mon Aug 08, 2011 12:12 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
Code:
ids = self.search(cr, user, ['|','|',('name',operator,name),('default_code',operator,name),('description',operator,name)] + args, limit=limit, context=context)


Something like that.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: what happened with name_search function?
PostPosted: Mon Aug 08, 2011 12:36 pm 
Offline

Joined: Tue Jan 18, 2011 5:16 pm
Posts: 236
Oh, thanks!

I've already done that, only difference is the extra '|' , what is this here for?

Thanks

_________________
OpenERP debugging with Eclipse on headless server


Top
 Profile  
 
 Post subject: Re: what happened with name_search function?
PostPosted: Mon Aug 08, 2011 12:44 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
they are prefix operators, | means OR. You have 3 terms so you want A OR B OR C, without it you have A or (B AND C)

_________________
Graeme


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP