summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2019-10-15 13:26:22 +0000
committerfw-bot <otis@odoo.com>2019-10-22 14:55:51 +0000
commitc8dca514e619741c9235fa5ad3e53693f65079e5 (patch)
treed5e1e683494c59a6189158daaccff0709ffa116e /odoo/fields.py
parent5efd768b3da3ce38338ae6a33cd1c9c87efc7424 (diff)
[FIX] fields: `compute_sudo` defaults to True for stored fields only
The default `compute_sudo=True` makes sense for recomputing stored fields that are indirectly related to a business operation. This ensures that the recomputation of the field does not break an operation that is not aware of the fields to recompute. However, computing non-stored fields in superuser mode is usually not necessary. It even leads to unexpected values: counting a partner's sales orders does not give the same result in superuser mode as in normal mode. That is why non-stored fields are not computed in superuser mode by default. [FIX] account, delivery, event, hr_recruitment, point_of_sale, stock: adapt the model definition to make all fields with the same compute method have the same value for `compute_sudo`. [FIX] sale: split the computation of `invoice_ids`, `invoice_count` (non-stored) and `invoice_status` (stored), as no code is actually shared. closes odoo/odoo#39195 X-original-commit: 843fd38a97f02b49dc09d7f55919072d272fd80e Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index 720c3bcb7c0..1eaaeb4a2a1 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -153,8 +153,9 @@ class Field(MetaField('DummyField', (object,), {})):
:param store: whether the field is stored in database (boolean, by
default ``False`` on computed fields)
- :param compute_sudo: whether the field should be recomputed as superuser
- to bypass access rights (boolean, by default ``True``)
+ :param compute_sudo: whether the field should be computed in superuser
+ mode to bypass access rights (boolean, defaults to ``True`` for
+ stored fields and ``False`` for non-stored fields)
The methods given for ``compute``, ``inverse`` and ``search`` are model
methods. Their signature is shown in the following example::
@@ -295,7 +296,7 @@ class Field(MetaField('DummyField', (object,), {})):
'depends_context': None, # collection of context key dependencies
'recursive': False, # whether self depends on itself
'compute': None, # compute(recs) computes field on recs
- 'compute_sudo': True, # whether field should be recomputed as superuser
+ 'compute_sudo': False, # whether field should be recomputed as superuser
'inverse': None, # inverse(recs) inverses field on recs
'search': None, # search(recs, operator, value) searches on self
'related': None, # sequence of field names, for related fields
@@ -415,18 +416,24 @@ class Field(MetaField('DummyField', (object,), {})):
# initialize ``self`` with ``attrs``
if attrs.get('compute'):
- # by default, computed fields are not stored, not copied and readonly
- attrs['store'] = attrs.get('store', False)
+ # by default, computed fields are not stored, computed in superuser
+ # mode if stored, not copied and readonly
+ attrs['store'] = store = attrs.get('store', False)
+ attrs['compute_sudo'] = attrs.get('compute_sudo', store)
attrs['copy'] = attrs.get('copy', False)
attrs['readonly'] = attrs.get('readonly', not attrs.get('inverse'))
if attrs.get('related'):
- # by default, related fields are not stored and not copied
- attrs['store'] = attrs.get('store', False)
+ # by default, related fields are not stored, computed in superuser
+ # mode, not copied and readonly
+ attrs['store'] = store = attrs.get('store', False)
+ attrs['compute_sudo'] = attrs.get('compute_sudo', attrs.get('related_sudo', True))
attrs['copy'] = attrs.get('copy', False)
attrs['readonly'] = attrs.get('readonly', True)
if attrs.get('company_dependent'):
- # by default, company-dependent fields are not stored and not copied
+ # by default, company-dependent fields are not stored, not computed
+ # in superuser mode and not copied
attrs['store'] = False
+ attrs['compute_sudo'] = attrs.get('compute_sudo', False)
attrs['copy'] = attrs.get('copy', False)
attrs['default'] = attrs.get('default', self._default_company_dependent)
attrs['compute'] = self._compute_company_dependent
@@ -439,8 +446,6 @@ class Field(MetaField('DummyField', (object,), {})):
attrs['depends_context'] = attrs.get('depends_context', ()) + ('lang',)
if 'depends' in attrs:
attrs['depends'] = tuple(attrs['depends'])
- if 'related_sudo' in attrs:
- attrs['compute_sudo'] = attrs['related_sudo']
return attrs