[FIX] product: name_search result

The function "name_search" defined on "product.template" made a search on
"product.product" name to give the "product.template" which matched with the
search. The number of results given by the name_search on "product.product" is
generally limited to 8. The problem was when for example there were 8 variants ("product.product")
with a name begining by "AA" for the same "product.template" T1 and another "product.product"
with a name begining by "AB" linked to T2. In this situation, if a name_search was made on "product.template" with a name="A",
the result got was just the the name of T1 linked to the 8 variants instead of the name of the
two templates (T1 and T2) due to the limitation.

opw:647066
This commit is contained in:
Goffin Simon 2015-08-26 10:18:40 +02:00
parent 19e9163367
commit 4b6309f5de
1 changed files with 13 additions and 7 deletions

View File

@ -821,18 +821,24 @@ class product_template(osv.osv):
if not name or any(term[0] == 'id' for term in (args or [])):
return super(product_template, self).name_search(
cr, user, name=name, args=args, operator=operator, context=context, limit=limit)
template_ids = set()
product_product = self.pool['product.product']
results = product_product.name_search(
cr, user, name, args, operator=operator, context=context, limit=limit)
results = product_product.name_search(cr, user, name, args, operator=operator, context=context, limit=limit)
product_ids = [p[0] for p in results]
template_ids = [p.product_tmpl_id.id
for p in product_product.browse(
cr, user, product_ids, context=context)]
for p in product_product.browse(cr, user, product_ids, context=context):
template_ids.add(p.product_tmpl_id.id)
while (results and len(template_ids) < limit):
domain = [('product_tmpl_id', 'not in', list(template_ids))]
results = product_product.name_search(
cr, user, name, args+domain, operator=operator, context=context, limit=limit)
product_ids = [p[0] for p in results]
for p in product_product.browse(cr, user, product_ids, context=context):
template_ids.add(p.product_tmpl_id.id)
# re-apply product.template order + name_get
return super(product_template, self).name_search(
cr, user, '', args=[('id', 'in', template_ids)],
cr, user, '', args=[('id', 'in', list(template_ids))],
operator='ilike', context=context, limit=limit)
class product_product(osv.osv):