← Back to team overview

openerp-community team mailing list archive

[Merge] lp:~openerp-community/openobject-addons/trunk-bugfix-768994 into lp:openobject-addons

 

Jacques-Etienne Baudoux (OpenERP) has proposed merging lp:~openerp-community/openobject-addons/trunk-bugfix-768994 into lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #768994 in OpenERP Addons: "improve name search an analytic account"
  https://bugs.launchpad.net/openobject-addons/+bug/768994

For more details, see:
https://code.launchpad.net/~openerp-community/openobject-addons/trunk-bugfix-768994/+merge/58820
-- 
https://code.launchpad.net/~openerp-community/openobject-addons/trunk-bugfix-768994/+merge/58820
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openobject-addons/trunk-bugfix-768994.
=== modified file 'analytic/analytic.py'
--- analytic/analytic.py	2011-04-07 11:41:45 +0000
+++ analytic/analytic.py	2011-04-22 14:30:58 +0000
@@ -150,7 +150,7 @@
     _columns = {
         'name': fields.char('Account Name', size=128, required=True),
         'complete_name': fields.function(_complete_name_calc, method=True, type='char', string='Full Account Name'),
-        'code': fields.char('Account Code', size=24),
+        'code': fields.char('Account Code', size=24, select=True),
         'type': fields.selection([('view','View'), ('normal','Normal')], 'Account Type', help='If you select the View Type, it means you won\'t allow to create journal entries using that account.'),
         'description': fields.text('Description'),
         'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', select=2),
@@ -245,13 +245,23 @@
             cr.execute("select analytic_account_id from project_project")
             project_ids = [x[0] for x in cr.fetchall()]
             return self.name_get(cr, uid, project_ids, context=context)
-        account = self.search(cr, uid, [('code', '=', name)] + args, limit=limit, context=context)
-        if not account:
-            account = self.search(cr, uid, [('name', 'ilike', '%%%s%%' % name)] + args, limit=limit, context=context)
-            newacc = account
-            while newacc:
-                newacc = self.search(cr, uid, [('parent_id', 'in', newacc)]+args, limit=limit, context=context)
-                account += newacc
+        if name:
+            account = self.search(cr, uid, [('code', '=', name)] + args, limit=limit, context=context)
+            if not account:
+                names=map(lambda i : i.strip(),name.split('/'))
+                for i in range(len(names)):
+                    dom=[('name', operator, names[i])]
+                    if i>0:
+                        dom+=[('id','child_of',account)]
+                    account = self.search(cr, uid, dom, limit=limit, context=context)
+                newacc = account
+                while newacc:
+                    newacc = self.search(cr, uid, [('parent_id', 'in', newacc)], limit=limit, context=context)
+                    account += newacc
+                if args:
+                    account = self.search(cr, uid, [('id', 'in', account)] + args, limit=limit, context=context)
+        else:
+            account = self.search(cr, uid, args, limit=limit, context=context)
         return self.name_get(cr, uid, account, context=context)
 
 account_analytic_account()


Follow ups