summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2015-06-16 17:41:33 +0200
committerRaphael Collet <rco@openerp.com>2015-06-17 10:48:29 +0200
commitdca1894b5d3567cb1ed209ce1069dc365489d0e6 (patch)
treebb5da5890c540721fa49c1750a4d365da8cfb043 /addons
parentd15322ae340711da77f484a8073992ac912078b4 (diff)
[IMP] product: optimize `name_get()` of `product.category`
Using the new API takes better advantage of the cache than calling `read()`. In the list of products, `name_get()` now generates 2 queries instead of 144!
Diffstat (limited to 'addons')
-rw-r--r--addons/product/product.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/addons/product/product.py b/addons/product/product.py
index c96926dd35d..30ee7a9a9b7 100644
--- a/addons/product/product.py
+++ b/addons/product/product.py
@@ -25,8 +25,7 @@ import time
from _common import ceiling
-from openerp import SUPERUSER_ID
-from openerp import tools
+from openerp import api, tools, SUPERUSER_ID
from openerp.osv import osv, fields, expression
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
@@ -235,19 +234,17 @@ class product_ul(osv.osv):
#----------------------------------------------------------
class product_category(osv.osv):
- def name_get(self, cr, uid, ids, context=None):
- if isinstance(ids, (list, tuple)) and not len(ids):
- return []
- if isinstance(ids, (long, int)):
- ids = [ids]
- reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
- res = []
- for record in reads:
- name = record['name']
- if record['parent_id']:
- name = record['parent_id'][1]+' / '+name
- res.append((record['id'], name))
- return res
+ @api.multi
+ def name_get(self):
+ def get_names(cat):
+ """ Return the list [cat.name, cat.parent_id.name, ...] """
+ res = []
+ while cat:
+ res.append(cat.name)
+ cat = cat.parent_id
+ return res
+
+ return [(cat.id, " / ".join(reversed(get_names(cat)))) for cat in self]
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
if not args: