title: odoo filter one2many list
body: <p>I have a long one2many list and want to show only a subset of this to the user, based on filters that the user may set.</p>
  
  <p>My <strong>current approach</strong> is to have the original one2many field with all records, and another filtered one2many field.
  I compute the filtered list by selecting the subset that is not filtered from the original list.
  Further I apply the changes from the filtered list to the original list. So I search for new records in the list and create those as well in the original list. I search for deleted records and delete them from the original list.</p>
  
  <p>This approach works actually, but it requires a bunch of code and only mimics what I would expect from either some native Odoo features or a filterable one2many widget.</p>
  
  <p>Sadly all <strong>other approaches</strong> I tried did not work:</p>
  
  <ul>
  <li>Searching in one2many lists does not work (e.g. setting <code>search_default_</code> values in the context). I think it is not supported.</li>
  <li>Using a domain to filter the second one2many list does not work (neither in xml nor python code). I think Odoo only allows this for many2many.</li>
  <li>I would like to create a filterable one2many widget by extending the normal one. However I don't understand where in the js code the list is populated.</li>
  </ul>
  
  <p>So question is: Is there an easier solution than my current approach to filter a one2many field with native Odoo features?
  Or can you help me with the js code of a custom one2many widget to only show a subset of items? For instance, which method is called when the list is populated and in which field are the ids of the items?</p>
  
  <p><strong>Example</strong></p>
  
  <p>I want in my model something as the following:</p>
  
  <pre><code># This is the original list, with all entries
  schedule_entry_ids =
      fields.One2many('mymodule.schedule_entry', 'schedule_id', string="Entries")
  
  # This is the filtered list, to be used in the view
  # Note: Sadly using the domain here does not work. It always shows all entries. But I hope you get the idea what I want to accomplish.
  filtered_schedule_entry_ids =
      fields.One2many('mymodule.schedule_entry', string="Filtered Entries", related='schedule_entry_ids', domain='[("phase_id", "=", filter_phase_id)]')
  
  # This is the field that defines the filter
  filter_phase_id =
      fields.Many2one('mymodule.phase', string="Phase Filter")
  </code></pre>
  
  <p>Sadly using the domain filter does not work, so my approach at the moment is to create the filtered field as a computed field 'by hand':</p>
  
  <pre><code>filtered_schedule_entry_ids =
      fields.One2many('mymodule.schedule_entry', string="Filtered Entries", compute='_compute_filter', inverse='_inverse_filter')
  
  @api.onchange('filter_phase_id', 'schedule_entry_ids')
  def _compute_filter(self):
      # Populate the filtered list with the elements from the original list, for which the filter condition holds
  
  def _inverse_filter(self):
      # Remove elements from the original list if they should be present in the filtered list but aren't anymore (elements have been deleted from the filtered list).
      # For all new elements in the filtered list, create a new element in the original list (elements have been created)
  </code></pre>