title: Odoo: Values of Many2many with dynamic domain aren't getting saved
body: <p>I am trying to dynamically change the values of a <code>many2many</code> field <code>products_ids</code> based on multiple <code>onchange</code> functions of other fields (e.g. <code>brand_id</code> and <code>origin_id</code>).
  So far everything is working great and it does show the expected values, but once i hit the save button the values of the <code>many2many</code> field disappear</p>
  <p><a href="https://i.stack.imgur.com/4KLfk.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4KLfk.gif" alt="enter image description here" /></a></p>
  <pre><code>class CustomModifyPrice(models.Model):
      brand_id = fields.Many2many(comodel_name=&quot;custom.brand&quot;, string=&quot;Brand&quot;, required=False, )
      origin_id = fields.Many2many(comodel_name=&quot;custom.country&quot;, string=&quot;Origin&quot;, required=False, )
      product_ids = fields.Many2many(comodel_name=&quot;custom.product&quot;, string=&quot;Products&quot;, readonly=True, )
      search_terms = {}
      product_ids_list = []
  
      @api.onchange('brand_id')
      def onchange_change_brand(self):
          for rec in self:
              product_brands = []
              for prod_brand in rec.brand_id:
                  product_brands.append(prod_brand.id)
              rec.search_terms[&quot;product_brands&quot;] = product_brands
              rec.get_products()
  
      @api.onchange('origin_id')
      def onchange_change_origin(self):
          for rec in self:
              product_origins = []
              for prod_origin in rec.origin_id:
                  product_origins.append(prod_origin.id)
              rec.search_terms[&quot;product_origins&quot;] = product_origins
              rec.get_products()
  
      def get_products(self):
          domain = []
          self.product_ids_list = []
          if 'product_brands' in self.search_terms:
              product_brands = self.search_terms['product_brands']
              if product_brands:
                  tuple1 = ('brand_id', 'in', product_brands)
                  domain.append(tuple1)
  
          if 'product_origins' in self.search_terms:
              product_origins = self.search_terms['product_origins']
              if product_origins:
                  tuple1 = ('country_id', 'in', product_origins)
                  domain.append(tuple1)
  
          if domain:
              products = self.env['custom.product'].search(domain)
              if products.ids:
                  for prod in products:
                      self.product_ids_list.append(prod.id)
              self.product_ids = [(6, False, self.product_ids_list)]
  </code></pre>