From 2d83656c0fe8d6c37913a19a73aa5a6e65acc72a Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 24 Jul 2015 16:37:19 +0200 Subject: [PATCH] [FIX] analytic: multi-path name_search should properly handle `limit` Due to commit 1576bc98919c1ae93e66f902fb5c700c61c2b6cf, 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. --- addons/analytic/analytic.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index 7bb6c1642ff..975b8d6b63a 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -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):