[FIX] product: avoid duplicates in name search
A typo probably introduced during the migration to the new api may have
caused duplicates to appear in the name search results since it added
the ids of the wrong recordset.
The previous fix, while effective, also removed a previous optimization
for databases with a lot of products. While the code may seem obscure
on first read, the comments should shed some light on the
implementation choice.
This commit therefore reintroduce the previous code with the exception
of the call to the wrong recordset (self instead of products).
Amends b02a85f
Courtesy of @rco-odoo
This commit is contained in:
@@ -425,7 +425,11 @@ class ProductProduct(models.Model):
|
||||
# on a database with thousands of matching products, due to the huge merge+unique needed for the
|
||||
# OR operator (and given the fact that the 'name' lookup results come from the ir.translation table
|
||||
# Performing a quick memory merge of ids in Python will give much better performance
|
||||
products = self.search(args + ['|', ('default_code', operator, name), ('name', operator, name)], limit=limit)
|
||||
products = self.search(args + [('default_code', operator, name)], limit=limit)
|
||||
if not limit or len(products) < limit:
|
||||
# we may underrun the limit because of dupes in the results, that's fine
|
||||
limit2 = (limit - len(products)) if limit else False
|
||||
products += self.search(args + [('name', operator, name), ('id', 'not in', products.ids)], limit=limit2)
|
||||
elif not products and operator in expression.NEGATIVE_TERM_OPERATORS:
|
||||
products = self.search(args + ['&', ('default_code', operator, name), ('name', operator, name)], limit=limit)
|
||||
if not products and operator in positive_operators:
|
||||
|
||||
Reference in New Issue
Block a user