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>The documentation on writing to related fields <a href="https://www.odoo.com/documentation/8.0/reference/orm.html" rel="nofollow">ORM Documentation</a> speaks of the (2,_,ids) as a method which cant be used in create. If you are writing you can do the following.</p>

<p>If you overwrite the write() function you could probably put some logging in as well as (depending on the reason for Odoo's behaviour) force the record to write the way you are hoping to.</p>

<pre><code>@api.multi
def write(self, vals):
    _logger = logging.getLogger(__name__)
    _logger.info("PREPARING TO WRITE RECORD")
    _logger.info("WRITING VALS: " + str(vals))
    return super(Schedule, self).write(vals)
</code></pre>

python openerp edit v8