summaryrefslogtreecommitdiff
path: root/odoo/api.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2018-11-22 14:32:11 +0000
committerRaphael Collet <rco@odoo.com>2018-11-23 11:18:19 +0000
commit499cdd57083da462eec0a66bf76be18a3c703101 (patch)
tree728ea9298a5865638e94412231f7b6ca338b74fc /odoo/api.py
parent264f89f63f89678b01a75a20b508dd10018b00d8 (diff)
[FIX] fields: combine special values during onchange
Consider a many2one field `foo_id` on model `bar`, with an inverse one2many field `bar_ids` on model `foo`. During an onchange, the statement bar.foo_id = foo puts a special value in cache to add `bar` to the value of `foo.bar_ids` without explicitly reading `foo.bar_ids`. Executing the above statement a second time, the cache of `foo.bar_ids` is no longer empty. This causes the actual value of `foo.bar_ids` to be read and updated. The issue is that this can be slow for large values of `foo.bar_ids`. Avoid reading the value of the one2many field by handling the case where the cache contains the special value: simply update the special value to take into account the second assignment. closes odoo/odoo#28982
Diffstat (limited to 'odoo/api.py')
-rw-r--r--odoo/api.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/odoo/api.py b/odoo/api.py
index 21095854a70..903e1187329 100644
--- a/odoo/api.py
+++ b/odoo/api.py
@@ -982,6 +982,12 @@ class Cache(object):
value = self._data[field][record.id].get(key, SpecialValue(None))
return default if isinstance(value, SpecialValue) else value
+ def get_special(self, record, field, default=None):
+ """ Return the special value of ``field`` for ``record``. """
+ key = field.cache_key(record)
+ value = self._data[field][record.id].get(key)
+ return value.get if isinstance(value, SpecialValue) else default
+
def set_special(self, record, field, getter):
""" Set the value of ``field`` for ``record`` to return ``getter()``. """
key = field.cache_key(record)