Use of domain in search of One2many field in List view in Odoo-9
<p>i have One2many field <b>product_attributes</b> in <b>product.template</b> and <b>value</b> field in <b>product.attributes.custom</b></p>

<pre><code>class ProductTemplateCus(models.Model):
    _inherit = 'product.template'
    product_attributes = fields.One2many('product.attributes.custom','product_id')

class ProductAttributes(models.Model):
    _name = 'product.attributes.custom'
    value = fields.Char(string='Value')
    product_id = fields.Many2one('product.template',string='Product')
</code></pre>

<p>Product 1 <b>product_attributes</b> contains 2 values:</p>

<pre><code>value= 'color: red'
value= 'others: red'
</code></pre>

<p>product 2 <b>product_attributes</b> contains 2 values:</p>

<pre><code>value= 'color: white'
value= 'others: red'
</code></pre>

<p>I did like below in search xml:</p>

<pre><code>&lt;field 
name="product_attributes" string="Color"
filter_domain="['&amp;amp;',('product_attributes.value','ilike','color'),('product_attributes.value','ilike',self)]"
/&gt;
</code></pre>

<p>So if <b>red</b> is searched, only product 1 containing both <b>color</b> and <b>red</b> should be shown. But I am unable to get result. I am getting both products.</p>

<p>Is there any solution for this?</p>

<p>There are a few types of domain for field in the search view:</p>

<ul>
<li><code>domain</code> - just like the domain on the field declaration in the python class, limits the records got from the database;</li>
<li><code>filter_domain</code> - overrides the <code>name_search</code> method which would normally have only <code>('name', 'ilike', self)</code>.</li>
</ul>

<p>In your case, I believe, you need the <code>filter_domain</code>.</p>

<hr>

<p>Just a suggestion, you could add the <code>:</code> after the attribute name to differentiate between the attribute and its value, given that you use the same convention for all your attributes: 
<code>('product_attributes.value', 'ilike', 'color: ')</code></p>

<p>The default operator between domains is <code>&amp;</code> and in this case can be omitted.</p>

python listview openerp odoo-9