[MERGE] forward port branch 11.0 up to bb6f6c57f9
This commit is contained in:
+27
-12
@@ -2054,6 +2054,26 @@ class Many2one(_Relational):
|
||||
return super(Many2one, self).convert_to_onchange(value, record, names)
|
||||
|
||||
|
||||
class _RelationalMultiUpdate(object):
|
||||
""" A getter to update the value of an x2many field, without reading its
|
||||
value until necessary.
|
||||
"""
|
||||
__slots__ = ['record', 'field', 'value']
|
||||
|
||||
def __init__(self, record, field, value):
|
||||
self.record = record
|
||||
self.field = field
|
||||
self.value = value
|
||||
|
||||
def __call__(self):
|
||||
# determine the current field's value, and update it in cache only
|
||||
record, field, value = self.record, self.field, self.value
|
||||
cache = record.env.cache
|
||||
cache.remove(record, field)
|
||||
val = field.convert_to_cache(record[field.name] | value, record, validate=False)
|
||||
cache.set(record, field, val)
|
||||
return val
|
||||
|
||||
|
||||
class _RelationalMulti(_Relational):
|
||||
""" Abstract class for relational fields *2many. """
|
||||
@@ -2065,21 +2085,16 @@ class _RelationalMulti(_Relational):
|
||||
""" Update the cached value of ``self`` for ``records`` with ``value``. """
|
||||
cache = records.env.cache
|
||||
for record in records:
|
||||
if cache.contains(record, self):
|
||||
special = cache.get_special(record, self)
|
||||
if isinstance(special, _RelationalMultiUpdate):
|
||||
# include 'value' in the existing _RelationalMultiUpdate; this
|
||||
# avoids reading the field's value (which may be large)
|
||||
special.value |= value
|
||||
elif cache.contains(record, self):
|
||||
val = self.convert_to_cache(record[self.name] | value, record, validate=False)
|
||||
cache.set(record, self, val)
|
||||
else:
|
||||
cache.set_special(record, self, self._update_getter(record, value))
|
||||
|
||||
def _update_getter(self, record, value):
|
||||
def getter():
|
||||
# determine the current field's value, and update it in cache only
|
||||
cache = record.env.cache
|
||||
cache.remove(record, self)
|
||||
val = self.convert_to_cache(record[self.name] | value, record, validate=False)
|
||||
cache.set(record, self, val)
|
||||
return val
|
||||
return getter
|
||||
cache.set_special(record, self, _RelationalMultiUpdate(record, self, value))
|
||||
|
||||
def convert_to_cache(self, value, record, validate=True):
|
||||
# cache format: tuple(ids)
|
||||
|
||||
Reference in New Issue
Block a user