odoo cache force save
<p>I am developing some tests which, as setup, requires to write some test records, while in executing calls a method which perform a <code>self.env.cr.execute</code> of a sql SELECT, but records written in the setup remain into the cache thus the execute returns nothing (I also checked that a <code>browse(&lt;id&gt;)</code> returns the record, while <code>select([('id','=',&lt;id&gt;)])</code> which is itself based on <code>execute</code>, doesn't.</p>

<p>I tried</p>

<pre><code>models = dict()
for field, cache in self.env.cache.iteritems():
    for id_, value in cache.iteritems():
        models.setdefault(field.model_name, list())
        models[field.model_name].append(id_)

for name, ids in models.iteritems():
    for record in self.env[name].browse(ids):
        record.write(record._convert_to_write(record._cache))
</code></pre>

<p>as suggested <a href="https://stackoverflow.com/questions/33254792/how-to-write-to-database-all-cache-in-odoo-environment">here</a>, and I also tried to commit (<code>self.env.cr.commit</code>) just after the setup, but result is the same.</p>

<p>Any ideas?</p>