title: How to keep the order of the records added in a many2many field the way I wrote them?
body: <p>I want to keep the order of the records in the many2many field, the way I added them using the write method, but Odoo use the alphanumerical order by default and overwrote the order I put them in. How can I keep it in the same order when I wrote them, is that possible ?
  Here is the model code:</p>
  <pre><code>    # -*- coding: utf-8 -*-
  
  from odoo import models, fields, api
  
  
  class projet_richat(models.Model):
      _inherit = 'project.task'
  
      competence_ids = fields.Many2many('competence.competence',string='Compétences')
      consultants=fields.Many2many('hr.employee', string=&quot;Consultants&quot;)
  
  
      def search_comp(self):
          if len(self.competence_ids) != 0:
              consults=self.env['hr.employee'].sudo().search([])
              list=[]
              for cmp in self.competence_ids:
                  print(cmp.competence)
                  for cons in consults:
                      print(cons.name)
                      for c in cons.competences:
                          if c.competence.competence==cmp.competence:
                              list.append((cons.id,c.competence.competence,c.niveau))
              sorted_by_level = sorted(list, key=lambda tup: tup[2], reverse=True)
              print(sorted_by_level)
              for sorted_cons in sorted_by_level:
                  self.write({'consultants': [[4, sorted_cons[0]]]})
  </code></pre>
  <p>and here is the view code:</p>
  <pre><code>    &lt;odoo&gt;
      &lt;data&gt;
          &lt;record model=&quot;ir.ui.view&quot; id=&quot;project_inherit_form&quot;&gt;
              &lt;field name=&quot;name&quot;&gt;project.inherit.form&lt;/field&gt;
              &lt;field name=&quot;model&quot;&gt;project.task&lt;/field&gt;
              &lt;field name=&quot;type&quot;&gt;form&lt;/field&gt;
              &lt;field name=&quot;inherit_id&quot; ref=&quot;project.view_task_form2&quot;/&gt;
  
              &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;
                  &lt;field name=&quot;user_ids&quot; position=&quot;before&quot;&gt;
  
                      &lt;field name=&quot;competence_ids&quot; widget=&quot;many2many_tags&quot;/&gt;
  
  
                  &lt;/field&gt;
                  &lt;field name=&quot;parent_id&quot; position=&quot;after&quot;&gt;
  
  
                      &lt;field name=&quot;consultants&quot;&gt;
                          &lt;tree&gt;
  
                              &lt;field name=&quot;name&quot;/&gt;
  
  
                          &lt;/tree&gt;
                      &lt;/field&gt;
  
                  &lt;/field&gt;
                  &lt;button name=&quot;action_assign_to_me&quot; position=&quot;after&quot;&gt;
                      &lt;button name=&quot;search_comp&quot; string=&quot;Test&quot; class=&quot;btn-primary&quot;
                              type=&quot;object&quot;
                      /&gt;
                  &lt;/button&gt;
  
  
              &lt;/field&gt;
  
  
          &lt;/record&gt;
      &lt;/data&gt;
  &lt;/odoo&gt;
  </code></pre>
  <p>Thanks in advance.</p>