odoo: write function save old data
<p>I created an onchange function that link some object lines to the current one</p>

<pre><code>mo_lines_g1 = fields.One2many(comodel_name='object.order', inverse_name='mo_id1', copy=False )

@api.onchange('date')
def change_date(self):  
    if self.date:
        g1=self.env['object.order'].search(['&amp;'('date_order','&gt;=',self.date),('date_order','&lt;=',self.date)])
        self.mo_lines_g1 = [(6,0, g1.ids )]
</code></pre>

<p>here everything is ok, but when I save the view, Odoo try to delete the linked lines from the <code>object.order</code> 
<br/>
so I tried to see what the write function send I found it send the old records  :<br/>
 <code>vals[ 'mo_lines_g1'] = [[2, 61, False], [2, 62, False], [2, 63, False]]</code>
<br/>
normaly it must be :<br/> <code>vals['mo_lines_g1']=[] # or [(6,0,[])]</code>
<br/>
any ideas ?</p>

<p><code>(6, _, ids)</code> can not be used with One2many field.  </p>

<p>It is described at <a href="http://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html#x2many-values-filling" rel="nofollow">x2many values filling</a>.  </p>

python openerp edit v8