[英]How to write to database all cache in Odoo environment?
I'm doing a test where I need to imitate the onchange behavior, so: 我正在做一个需要模仿onchange行为的测试,所以:
with self.env.do_in_onchange():
self.onefield = "blahblah"
But when one exits the with block, that data is not written to DB. 但是,当退出with块时,该数据不会写入DB。 I'm looking for some kind of self.env.cache.write_to_db()
. 我正在寻找某种self.env.cache.write_to_db()
。 Do you know of any? 你知道吗
I found the solution. 我找到了解决方案。
To write a record's cache: 要写入记录的缓存:
self.write(self._convert_to_write(self._cache))
To write all the environment's cache: 要写入所有环境的缓存:
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.