[FIX] analytic: multi-path name_search should properly handle `limit`

Due to commit 1576bc9891,
when name_search() is called on analytic accounts with
multiple path components (e.g. A/B/C), the intermediary
searches are done without the extra domain criterions,
because they should only apply to the leaf.

However because the limit was applied for each step
of the multi-path search, it was quite likely that
no valid results were found in the final filtering,
returning no result at all.

In fact the intermediary steps should not apply the
limit at all, because the leaves we're looking for
may actually be located under parents that are not
found when the limit is applied on each step.

This commits removes the limit (hopefully without
too much of an extra penalty for large databases)

It also introduces a better fallback in case the
multi-path search did not produce any result,
for example if the name of the lead really contains
a '/', and it was not meant to be a path separator.
This commit is contained in:
Olivier Dony 2015-07-24 16:37:19 +02:00
parent b2193e6734
commit 2d83656c0f
1 changed files with 12 additions and 10 deletions

View File

@ -304,20 +304,22 @@ class account_analytic_account(osv.osv):
args=[]
if context is None:
context={}
account_ids = []
if name:
account_ids = self.search(cr, uid, [('code', '=', name)] + args, limit=limit, context=context)
if not account_ids:
dom = []
for name2 in name.split('/'):
name = name2.strip()
account_ids = self.search(cr, uid, dom + [('name', operator, name)], limit=limit, context=context)
if not account_ids: break
dom = [('parent_id','in',account_ids)]
if account_ids and args:
# final filtering according to domain (args)
account_ids = self.search(cr, uid, [('id', 'in', account_ids)] + args, limit=limit, context=context)
else:
account_ids = self.search(cr, uid, args, limit=limit, context=context)
if '/' in name:
for name2 in name.split('/'):
# intermediate search without limit and args - could be expensive for large tables if `name` is not selective
account_ids = self.search(cr, uid, dom + [('name', operator, name2.strip())], limit=None, context=context)
if not account_ids: break
dom = [('parent_id','in',account_ids)]
if account_ids and args:
# final filtering according to domain (args)4
account_ids = self.search(cr, uid, [('id', 'in', account_ids)] + args, limit=limit, context=context)
if not account_ids:
return super(account_analytic_account, self).name_search(cr, uid, name, args, operator=operator, context=context, limit=limit)
return self.name_get(cr, uid, account_ids, context=context)
class account_analytic_line(osv.osv):