title: openerp domain filter on a line item property
body: <p>I am trying to filter purchase orders based on a property of its line items. So, for example, I would like to see all purchase orders who have any line item with product_type = 'X'.</p>
  
  <pre><code>&lt;record id="po_x" model="ir.actions.act_window"&gt;
          &lt;field name="name"&gt;X Purchase Orders&lt;/field&gt;
          &lt;field name="type"&gt;ir.actions.act_window&lt;/field&gt;
          &lt;field name="res_model"&gt;purchase.order&lt;/field&gt;
          &lt;field name="view_type"&gt;form&lt;/field&gt;
          &lt;field name="view_mode"&gt;tree,form,calendar,graph,gantt&lt;/field&gt;
          &lt;field name="domain"&gt;[('has_x_line','=',True)]&lt;/field&gt;
          &lt;field name="context"&gt;{}&lt;/field&gt;
      &lt;/record&gt;
  </code></pre>
  
  <p>product_type is a custom field that I added to an inherited version of order line.</p>
  
  <pre><code>class purchase_order_custom(osv.osv):
      _name = 'purchase.order'
      _inherit = 'purchase.order'
  
      def linehasproducttype(self, cr, uid, ids, name, arg, context=None):
          cur_obj={}
          cur_obj=self.browse(cr, uid, ids, context=context)
          for line in cur_obj.order_line:
              if line.product_type == 'X':
                  return True
          return False
  
      _columns={
            'has_x_line': fields.function(linehasproducttype, string="Has X Line", type='boolean', context={'pt':'X'})
                }
  purchase_order_custom() 
  </code></pre>
  
  <p>2 questions:</p>
  
  <p>Q1. The above code is not working. That is, it is not really filtering as desired. What could be wrong?</p>
  
  <p>Q2. I have many product types and I am not inclined to make a function for each type. Can I pass an argument somehow or use the context for this purpose as I am trying to do? If so, how do I use it in the code?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong>: I have also tried the following code with no luck:</p>
  
  <pre><code>def linehasproducttype(self, cr, uid, ids, name, arg, context=None):
      res = dict.fromkeys(ids, False)
      for cur_obj in self.browse(cr, uid, ids, context=context):
          res[cur_obj.id] = False
          for line in cur_obj.order_line:
              if line.product_type == 'X':
                  res[cur_obj.id] = True
      return res
  </code></pre>