diff --git a/addons/product/product.py b/addons/product/product.py index 96317ad1aca..38c57377ab4 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -364,12 +364,12 @@ class product_attribute_line(osv.osv): # search on a m2o and one on a m2m, probably this will quickly become # difficult to compute - check if performance optimization is required if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'): - new_args = ['|', ('attribute_id', operator, name), ('value_ids', operator, name)] - else: - new_args = args + args = ['|', ('attribute_id', operator, name), ('value_ids', operator, name)] + ids = self.search(cr, uid, args, limit=limit, context=context) + return self.name_get(cr, uid, ids, context=context) return super(product_attribute_line, self).name_search( cr, uid, name=name, - args=new_args, + args=args, operator=operator, context=context, limit=limit) diff --git a/addons/product/tests/__init__.py b/addons/product/tests/__init__.py index 7c05b1bf791..962cae5c595 100644 --- a/addons/product/tests/__init__.py +++ b/addons/product/tests/__init__.py @@ -1 +1 @@ -from . import test_uom, test_pricelist +from . import test_uom, test_pricelist, test_variants diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py new file mode 100644 index 00000000000..83d39197d7b --- /dev/null +++ b/addons/product/tests/test_variants.py @@ -0,0 +1,37 @@ +from openerp.tests.common import TransactionCase + +class TestVariants(TransactionCase): + + def setUp(self): + res = super(TestVariants, self).setUp() + self.size_attr = self.env['product.attribute'].create({'name': 'Size'}) + self.size_attr_value_s = self.env['product.attribute.value'].create({'name': 'S', 'attribute_id': self.size_attr.id}) + self.size_attr_value_m = self.env['product.attribute.value'].create({'name': 'M', 'attribute_id': self.size_attr.id}) + self.size_attr_value_l = self.env['product.attribute.value'].create({'name': 'L', 'attribute_id': self.size_attr.id}) + self.product_shirt_template = self.env['product.template'].create({ + 'name': 'Shirt', + 'attribute_line_ids': [(0, 0, { + 'attribute_id': self.size_attr.id, + 'value_ids': [(6, 0, [self.size_attr_value_l.id])], + })] + }) + return res + + def test_attribute_line_search(self): + search_not_to_be_found = self.env['product.template'].search( + [('attribute_line_ids', '=', 'M')] + ) + self.assertNotIn(self.product_shirt_template, search_not_to_be_found, + 'Shirt should not be found searching M') + + search_attribute = self.env['product.template'].search( + [('attribute_line_ids', '=', 'Size')] + ) + self.assertIn(self.product_shirt_template, search_attribute, + 'Shirt should be found searching Size') + + search_value = self.env['product.template'].search( + [('attribute_line_ids', '=', 'L')] + ) + self.assertIn(self.product_shirt_template, search_value, + 'Shirt should be found searching L')