[FIX] product: can't search attribute value
A name_search on attribute line would possibly ends up with a domain like:
['|', ('attribute_id', '=', 'm'), ('value_ids', '=', 'm'),
('attribute_id', '=', 'm')]
which would just search the attribute.
This is caused by calling the default name_search. This commit forgo
the default name_search when we are in this attribute line special case.
courtesy-of: @fmdl
opw-813505
closes #22619
closes #22760
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
from . import test_uom, test_pricelist
|
||||
from . import test_uom, test_pricelist, test_variants
|
||||
|
||||
@@ -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')
|
||||
Reference in New Issue
Block a user